0
Why does this not work? if(10<=a<=15) in js
Code let a=20 if (10<=a<=15){ console.log("hello") } It still prints hello https://code.sololearn.com/Wx34itpKvPPi/?ref=app
3 Answers
+ 8
The expression 10 <= a <= 15 is evaluated from left to right. Here I added parentheses to get you to understand, how the expression evaluation was performed.
( 10 <= a ) <= 15
( true ) <= 15
( 1 ) <= 15
This eventually, evaluates to true, hence the `if` block was entered.
You probably were trying to achieve this
if( 10 <= a && a <= 15 )
+ 4
let a=20
//10<=a -> True
//True<=15 -> True
if (10<a<15==true==1) {
console.log("HELLO!š")
}