jirengu / frontend-interview

前端笔试面试题题库
1.29k stars 139 forks source link

JS 相等比较相关 #24

Open oceanpad opened 7 years ago

oceanpad commented 7 years ago

请依次计算下列输出的值:

console.log( +0 ==  -0 )
console.log( +0 === -0 )
console.log( Object.is(+0, -0) )

console.log( "1" == 1 )
console.log( "1" === 1 )
console.log( Object.is("1", 1) )

console.log( new String("foo") == new String("foo") )
console.log( new String("foo") === new String("foo") )
console.log( Object.is(new String("foo") , new String("foo") ) )

console.log( new String("foo") == "foo" )
console.log( new String("foo") === "foo" )
console.log( Object.is(new String("foo") , "foo" ) )

const a = {}
const b = a 
console.log( a == b  )
console.log( a === b  )
console.log( Object.is(a, b) )

console.log( NaN == NaN )
console.log( NaN === NaN )
console.log( Object.is(NaN, NaN) )
RookieDay commented 7 years ago

下面是我的理解,有什么问题还望指正

mdn

oceanpad commented 7 years ago

@RookieDay 非常感谢提醒,已经修改成英字""。

MrZWH commented 7 years ago

@RookieDay 你给的链接都404了(:з」∠)