title: Global variable passed between functions jQuery
body: <p>I am setting a variable in an if...else statement. However, when I try to call the variable in another function, I get the error that the variable is not defined. How can I set a global variable?</p>
  
  <pre><code>function username_check(){  
  username = $('#username').val();
  if(username == "" || username.length &lt; 7 || username.indexOf(' ') &gt; -1){
      usernameFilled = 0;
  else{
      usernameFilled = 1;
  }   
  }
  
  function email_check(){ 
  email = $('#email').val();
  if(email == "" || email.indexOf(' ') &gt; -1) {
      emailFilled = 0;
  }else{
      emailFilled = 1;
  }
  }
  
  function password_length(){ 
  password = $('#password').val();
  if(password == "" || password.indexOf(' ') &gt; -1) {
      passwordFilled = 0;
  }else{
      passwordFilled = 1;
  }
  }
  
  function password_check(){  
    password2 = $('#password2').val();
    password = $('#password').val();
    if(password2.length &gt; 7 &amp;&amp; password2 == password) {
      password2Filled = 1; /**setting the variable**/
    }else{
      password2Filled = 0;
    }
  }
  
  function upload(){
  if (usernameFilled == 0 || emailFilled == 0 || passwordFilled == 0 || password2Filled == 0) {
      alert('All fields are required');
  }else{
      /**upload to database**/
  }
  </code></pre>