+ 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.

8th Jul 2020, 5:41 PM
Juvenal Martins dos Santos Netto
Juvenal Martins dos Santos Netto - avatar
1 Answer
8th Jul 2020, 5:46 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar