Ask Your Question
0

Why does the Javascript operator return a false output when checking if 1 is equal to 1 less than 3 (1===1<3)?

asked 2021-05-19 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-08-22 08:00:00 +0000

nofretete gravatar image

The comparison operator "<" has a higher precedence than the equality operator "===", which means that "1<3" will be evaluated first, resulting in the boolean value true. Then the comparison "1===true" is evaluated, which will return false because they are not equal in type or value.

To check if 1 is equal to 1 less than 3, you can use parentheses to group the comparison "1<3" and then compare it to 1 using the equality operator as follows:

(1 === (1 < 3))

This will return true because (1<3) will be evaluated to true, and then the comparison "1===true" is not made.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-19 11:00:00 +0000

Seen: 13 times

Last updated: Aug 22 '22