Boolean() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
20th Mar 2019, 6:16 PM
Solo
Solo - avatar
2 Answers
+ 15
//This returns true var a = Boolean("A"); //true while(a){ //This converts 'a'(true) to number 1 // here 'a' is 1 let my = a+10; //This makes 'a' false so the loop stops a = Boolean(); //This logs 11(because true + 10 is 11) console.log(my); }
20th Mar 2019, 6:28 PM
VEDANG
VEDANG - avatar
+ 2
VEDANG thanks! I also assumed that the mathematical calculation converts "true" to "1", but decided to make sure. ☺
20th Mar 2019, 6:57 PM
Solo
Solo - avatar