0

How the output is like below ?

var x = 18; if (x < 10) { console.log('You too much Young') } else if (x < 18) { console.log('You are still Minor') } else { console.log('You are allowed') } // Output : You are allowed

7th Apr 2020, 9:49 AM
Tusar
Tusar - avatar
2 ответов
+ 3
x == 18, so: + "if (x<10)" == "if (false)", so the if block (console.log('You too much young')) is not executed. + "else if (x<18)" == "if (false)" again: block skipped + "else", so in every other case (both x<10 and x<18 are false) execute console.log("You are allowed"): this was to be demontred ;) Notice that if (x<10) is true then (x<18) is also true ^^
7th Apr 2020, 10:19 AM
visph
visph - avatar
+ 1
Bcoz x<18 not = to 18. So the else part will be executed
7th Apr 2020, 10:14 AM
Riyaz Ali
Riyaz Ali - avatar