hello I've just started learning java script and i have a question about the if statement why when i assign a variable inside the if i don't need to add var before it and when i assign it outside if i must add var so why i can't add var inside the if () like this
if (var number = 5){
document.write("successful");
}
else{
document.write("failed");
}
and if i didn't add a var it assign the variable to the value like this
if (number = 5){
document.write("successful");
}
else{
document.write("failed");
}
i know it's a simple question but it got me confused
Aucun commentaire:
Enregistrer un commentaire