- 1
Questions from JS challenges!
1. alert(typeof ('bird' != 'cat')) Why answer is 'boolean'? 2. var y = true; var x = y || 1; alert(x) Why answer is true? 3. console.log(false + 7) Why answer is 7? 4. var x = 8; var a = (x++) % 3; document.write(a); The (x++) is it equal to 8?
2 Respuestas
+ 4
1: typeof 'bird'!='cat
'bird'!='cat is a boolean comparison that returns true since 'bird' is not 'cat'
and 'true' is of type boolean
2: var x=true|1;
true|1 returns the first truthy value in the sequence.true is the first truthy value so its returned;
3:false+7
false converted to a number has a value if 0,thus 0+7=0
4:x++ is post incrementation.the value of x is used on that line,then incremented on the other.
++x will yield 9
goodday
0
Thanks for your explanation!