Javascript Relational Operators Question 2

Introduction

What is the output of the following code?

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


true
true

Note

Take example 1:

Both operators are "<", so precedence is same

"<" is left to right associative

so first, 1 < 2 = true

true < 3

1 < 3 (coercion)

true

Take example 2:

Both operators are "<", so precedence is same

"<" is left to right associative

so first, 3 < 2 = false

false < 1

0 < 1 (coercion)

true (got the wrong result)




PreviousNext

Related