+ 8
Boolean()
Why is the code output 11? https://code.sololearn.com/W9TZiyHjuA3t/?ref=app
2 Antworten
+ 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);
}
+ 2
VEDANG thanks!
I also assumed that the mathematical calculation converts "true" to "1", but decided to make sure. ☺