if...elseステートメントで変数を設定しています。ただし、別の関数で変数を呼び出そうとすると、変数が定義されていないというエラーが表示されます。グローバル変数を設定するにはどうすればよいですか?
function username_check(){  
username = $('#username').val();
if(username == "" || username.length < 7 || username.indexOf(' ') > -1){
    usernameFilled = 0;
else{
    usernameFilled = 1;
}   
}
function email_check(){ 
email = $('#email').val();
if(email == "" || email.indexOf(' ') > -1) {
    emailFilled = 0;
}else{
    emailFilled = 1;
}
}
function password_length(){ 
password = $('#password').val();
if(password == "" || password.indexOf(' ') > -1) {
    passwordFilled = 0;
}else{
    passwordFilled = 1;
}
}
function password_check(){  
  password2 = $('#password2').val();
  password = $('#password').val();
  if(password2.length > 7 && 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**/
}