Boolean confusion in JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Boolean confusion in JS

A challange question I tried to recreate as JS code gave different results, I do not understand the reason. ( Tried looking for similar topics on boolean, but still confused.) The JS code is: let a=0, b=2; // the first time will result in 0 document.write(a++&&++b); console.log(Boolean(a) +" a"); console.log(Boolean(b) +" b"); console.log(Boolean(a++) +" a++"); console.log(Boolean(++b) +" ++b"); console.log(Boolean(a||b) +" a||b"); console.log(Boolean(a++&&++b ) +" a++&&++b"); // now the result is 5. Why? console.log(a++&&++b);

30th Jul 2019, 8:16 AM
Somgalagonya
0 Answers