true
//So, why not
null == 0 // outputs false ?
+null == 0 // But this outputs true
because don't use ==
https://thedevs.network/blog/type-coercion-in-javascript-and-why-everyone-gets-it-wrong
.
Because someone a long time ago thought it would be a good idea, mainly related to if (something). In hindsight, it was a terrible idea. It is quirky, unintuitive, and error prone. It can't be changed because of backward compatibility. Use === instead
Don't use +null, or +someVar, use Number(someVar)
Because null is an object so it gets coerced to a string by == and 'null' !== '0'.
Обсуждают сегодня