Javascript logical “!==” operator?

前端 未结 6 1949
无人共我
无人共我 2021-02-01 12:37

I am getting back into web development, and have been trying to go over the nuances of jscript recently. I was pouring through the source of the THREEx extension library built o

6条回答
  •  一个人的身影
    2021-02-01 12:53

    Copied from the formal specification: ECMAScript 5.1 section 11.9.5

    11.9.4 The Strict Equals Operator ( === )

    The production EqualityExpression : EqualityExpression === RelationalExpression is evaluated as follows:

    1. Let lref be the result of evaluating EqualityExpression.
    2. Let lval be GetValue(lref).
    3. Let rref be the result of evaluating RelationalExpression.
    4. Let rval be GetValue(rref).
    5. Return the result of performing the strict equality comparison rval === lval. (See 11.9.6)

    11.9.5 The Strict Does-not-equal Operator ( !== )

    The production EqualityExpression : EqualityExpression !== RelationalExpression is evaluated as follows:

    1. Let lref be the result of evaluating EqualityExpression.
    2. Let lval be GetValue(lref).
    3. Let rref be the result of evaluating RelationalExpression.
    4. Let rval be GetValue(rref). Let r be the result of performing strict equality comparison rval === lval. (See 11.9.6)
    5. If r is true, return false. Otherwise, return true.

    11.9.6 The Strict Equality Comparison Algorithm

    The comparison x === y, where x and y are values, produces true or false. Such a comparison is performed as follows:

    1. If Type(x) is different from Type(y), return false.
    2. Type(x) is Undefined, return true.
    3. Type(x) is Null, return true.
    4. Type(x) is Number, then
      1. If x is NaN, return false.
      2. If y is NaN, return false.
      3. If x is the same Number value as y, return true.
      4. If x is +0 and y is -0, return true.
      5. If x is -0 and y is +0, return true.
      6. Return false.
    5. If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions); otherwise, return false.
    6. If Type(x) is Boolean, return true if x and y are both true or both false; otherwise, return false.
    7. Return true if x and y refer to the same object. Otherwise, return false.

提交回复
热议问题