Search code examples
javascriptboolean-expression

Why does `true ||1 === 1/3` returns true in JavaScript?


I know that the === operator is used to determine whether its both operands are equal and identical or not. That is to say that if left side operand has 1 then the right side operand must be 1 for returning true. but I don't get why javascript returns true for this calculation.

true || 1 === 1/3;

//true;

I don't get how this result can be true in JavaScript.


Solution

  • The === Operation will never be checked. The statement is true by true.

    Also see this question and answer on how if statements are evaluated.