+ 4

JAVASCRIPT COMPARISON OPERATORS

var x=3; if(x==3) { alert(“Hello”); } else if(x===3) { alert(“Hi”); } //Hi Please why is this so??

16th Nov 2019, 7:54 PM
Valentine
Valentine  - avatar
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
16th Nov 2019, 8:31 PM
Jax
Jax - avatar
+ 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
16th Nov 2019, 8:00 PM
Jax
Jax - avatar
+ 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” ??
16th Nov 2019, 8:26 PM
Valentine
Valentine  - avatar
+ 1
Oooookay 😅....Now I get it! Thanks so much 👌
16th Nov 2019, 8:34 PM
Valentine
Valentine  - avatar
+ 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
1st Dec 2020, 1:17 AM
BroFar
BroFar - avatar
- 2
Sooooooo lost😑🤔
18th Sep 2020, 4:13 PM
Cleopatra
Cleopatra - avatar
- 3
I'm still lost
18th Sep 2020, 4:12 PM
Cleopatra
Cleopatra - avatar