JavaScript is non-strictly typed language as Java,for example.
As we know, it converts value of result dependently upon context:
"2" + "3"
results "23"
"2" * "3"
results 6
This is quite clear and OK for understanding.
I just tried following expressions and got confused:
true && 1
results 1
true || 1
results true
Why the first gives Number and the second gives boolean?
Considering JavaScript conversion rules,I expect to get boolean
values in both cases,due to boolean
context of expression.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…