Value of:
true + 3 + '100' + null
The correct answer is A.
JavaScript evaluates the expression from left to right:
true + 3 + '100' + null
Step 1:
true + 3
In numeric addition, true is converted to:
1
So:
true + 3
becomes:
1 + 3
Result:
4
Step 2:
4 + '100'
Because one operand is a string, JavaScript performs string concatenation instead of numeric addition.
So:
4 + '100'
becomes:
'4100'
Step 3:
'4100' + null
Again, because one operand is already a string, JavaScript converts null into the string:
'null'
So the final result is:
'4100null'
Execution summary:
true + 3 + '100' + null
// 1 + 3 + '100' + null
// 4 + '100' + null
// '4100' + null
// '4100null'
Therefore, the verified answer is A.
Currently there are no comments in this discussion, be the first to comment!