Strange code in jQuery sources: var !== var ? x : y;

前端 未结 3 1453
清酒与你
清酒与你 2020-12-08 00:31

Recently I found one weird line in the jQuery sources (last version 1.9.1, Sizzle package, line 129 funescape function):

funescape = function( _         


        
3条回答
  •  一生所求
    2020-12-08 01:10

    The condition high !== high returns true, when high is NaN.I wonder why the jQuery guys did not used the much clear isNaN(high) function instead, but that was probably due to performance reasons as koopajah pointed out.

    NaN (Not-a-Number) means a result that cannot be represented as a Number. It is an undeterminated number.


    Why NaN === NaN returns false ?

    Consider

    0/0          = NaN
    Math.asin(2) = NaN
    

    You know that 0/0 is different than Math.asin(2), so why whould NaN be equal to NaN?

提交回复
热议问题