I’m new to javascript and am having issues with a seemingly simple if/else statement.
Can anyone let me know why the below isn’t working please (Im pulling my hair out)
var is_expanded = false;
if (is_expanded==false) {
alert('no');
is_expanded = true;
} else {
alert('yes');
}
I always get the ‘no’ alert (I never get to the else part).
Cheers for any help.
You previous line of code says
var is_expanded = false;which means
if (is_expanded==false)will always evaluate totrue.So that is exactly what you are getting as output. What did you expect?
Next time when your same method is called, the value for
is_expandedis again reset tofalsedue to your first line of code. Then again it will alertno