+ 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 odpowiedzi
+ 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