+ 1
When type coercion should happens in Javascript comparisons?
How should I know when a "truthy" or "falsy" will be coerced into true or false when using the "==" operator for comparisons? For example "null" or "undefined" are "falsies", but can't be coerced to false using "==", but an empty string or 0 can, is it because of the type of undefined (undefined) or null (object)? NaN is number, a "falsy" and can't be coerced either (I know "NaN === NaN" is always false). I'm curious even though I know we should (at least almost) never use "==" instead of "===", but sometimes this type of knowledge is required even for some challenge questions here on Sololearn. Thanks in advance.
1 Resposta
+ 2
Here is full explanation
https://code.sololearn.com/W3CwqAGgJqRV/?ref=app