js value comparing two different types of Boolean (0 == '')

Write js problems encountered thought Boolean (0 == '') is true

However, the implementation of the console

Boolean(0==' ')
true
Boolean(0==null)
false

Baidu that, comparing two different types of values, wherein a is a number, the other is a string, the string will be first converted to digital, and digital comparison.

If you want to compare strings and 0 can be used ===, first determine whether the same type, and then determines whether or not the same value

Boolean(0===' ')
false

Guess you like

Origin www.cnblogs.com/yuanqt/p/11206999.html