misty0304 / day-interview

前端每日一题,提倡每日学习与思考,每天进步一点!
13 stars 1 forks source link

【js】写出如下代码的返回值,并解释为什么? #54

Open misty0304 opened 4 years ago

misty0304 commented 4 years ago
String('11') == new String('11');
String('11') === new String('11');
misty0304 commented 4 years ago

true false

解释: new String() 返回的是对象

== 的时候,实际运行的是 String('11') == new String('11').toString();是字符串与字符串对比,为true

=== 是字符串与对象对比,为false