+ 4
JAVASCRIPT COMPARISON OPERATORS
var x=3; if(x==3) { alert(āHelloā); } else if(x===3) { alert(āHiā); } //Hi Please why is this so??
7 Answers
+ 3
x!=1//False, because x == 1
x <= 1//True, because x is less than/equal to 1
x == 1//True, but the one before it was True first
+ 6
if(x == 3) //True{
alert("Hello")
else if(x === 3){//Also True, but never called because the if statement was true
alert("Hi")
}
Basically, they are both doing the same thing. It will never alert Hi, because if x === 3, x has to == 3, and therefore the else if statement will never be called
+ 1
Okay thanks. What about this š
var x= 1;
if(x!=1) {alert("Good");}
else if(x<=1){alert("Well");}
else if(x==1) {alert("Fine");}
It outputs āWellā ??
+ 1
Oooookay š
....Now I get it! Thanks so much š
+ 1
Cleopatra
Please do not create spam threads or add spammy comments to an existing thread. Both are seen as negative behavior.
Thanks and happy coding
https://code.sololearn.com/Wv5gTHy1N6Ji/?ref=app
- 2
Sooooooo lostšš¤
- 3
I'm still lost