Is it a bug in Ecmascript - /\S/.test(null) returns true?

后端 未结 2 1120
北荒
北荒 2020-12-06 14:33

Both in Actionscript3 and Javascript these statements give the same result:

/\\S/.test(null) => true  
/null/.test(null) => true  
/m/.test(null) =>         


        
2条回答
  •  长情又很酷
    2020-12-06 15:10

    null is an object, and when testing against objects (non-string), its first converted to string, then its giving you that result.

    You could try with /Number/.test(Number) or /String/.test(String), which would return true too.

    Probably String(null) is being called, which is 'null'

    String(Number) will give

    function Number() {
        [native code]
    }
    

    and /function Number/.test(Number) return true too

提交回复
热议问题