0

Why is this result?

document.write(1&&2)==2

14th Sep 2016, 9:12 AM
容道财
容道财 - avatar
3 Answers
+ 4
a&&b returns a if it it can be interpreted as false, and b otherwise. And any non-zero value is interpreted as true. So 1&&2 is evaluated as 2. (You see Venkatesh's answer? This is why you should words instead of ==. People confuses that with actual code.)
14th Sep 2016, 11:26 AM
Zen
Zen - avatar
+ 1
My guess is this will lead to compilation error. Because of braces placement. braces is only for a&&b and write will not return any values. So it will report an error
14th Sep 2016, 9:47 AM
Venkatesh(Venki)
Venkatesh(Venki) - avatar
- 5
hjkl
15th Sep 2016, 2:20 AM
Mohammed_el Amin Lemkhertat
Mohammed_el Amin Lemkhertat - avatar