Community

Discussion Board

Anonymous interview experiences, offers and career talk from frontend engineers.

g1imf

Interview Phone - Frontend Google

#google
05920

What do the following lines output, and why?

console.log(1 < 2 < 3);
console.log(3 > 2 > 1);

The first statement outputs true, as expected.

The second statement outputs false due to how the operator associativity for < and > works in JavaScript. It compares from left to right, so 3 > 2 > 1 translates to true > 1. Since true is equivalent to 1, it then compares 1 > 1, resulting in false.

No replies yet

Markdown supported. 20 more characters needed.