zoukankan      html  css  js  c++  java
  • 1 < 2 < 3为true, 3 > 2 > 1为false

    如题目,javascript的运算符有时很有趣,把它们粘到firefox上看看吧。

    为什么会这样呢?

    其实这是由从左到右比较,通过内部的ToNumber方法比较计算出来的

    3 > 2 > 1 → (3 > 2) > 1 → true > 1 → 1 > 1 → false
    

    反过来

    1 < 2 < 3 → (1 < 2) < 3 → true < 3 → 1 < 3 → true
    

    如果把大于号小于号改成==等,这也很有趣。1 == 1 == 1 为true, 2 == 2 == 2为false.

  • 相关阅读:
    原型污染
    C#之抛异常
    为什么['1', '7', '11'].map(parseInt) returns [1, NaN, 3]?
    Linux
    Linux
    Linux
    Linux
    Linux
    Linux
    其他
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/2259678.html
Copyright © 2011-2022 走看看