What will be the equivalent output of the following JavaScript code snippet? [code] x = ~-y; w = x = y = z; q = a?b:c?d:e?f:g; [/code]

Mỹ Duyên

New member
What will be the equivalent output of the following JavaScript code snippet?
Code:
x = ~-y;
w = x = y = z;
q = a?b:c?d:e?f:g;
A.
Code:
x = ~(-y); w = (x = (y = z));
q = a?b:(c?d:(e?f:g));
B.
Code:
x = a?b:(c?d:(e?f:g));
q = ~(-y); w = (x = (y = z));
C.
Code:
x = (x = (y = z));w = ~(-y);
q = a?b:(c?d:(e?f:g));
D.
Code:
x = ~(-y); w = (x = (y = z)); 
q = (c?d:(e?f:g));
 
Answer: a
Explanation: Brackets have higher precedence than any other operator. The placement of brackets results in the same result as without putting any bracket.
 

Tìm kiếm

Back
Top