I wouldn't go so far to call them sins, but I agree that you can easily be careless in this language. JavaScript is not the only weak typed language, though (take Lua or Python for example). Also, || still has its merits where you consciously want to catch all falsy values.
Falsiness and
||
are sins in JavaScript. Carelessness can lead to unexpected.??
is OK, but you have to be careful that BOTHnull
andundefined
are considered. Please read the specification carefully.?.
is so bad that it doesn't work withI wouldn't go so far to call them sins, but I agree that you can easily be careless in this language. JavaScript is not the only weak typed language, though (take Lua or Python for example). Also,
||
still has its merits where you consciously want to catch all falsy values.Also your syntax error is actually that, because the correct code would be
For the sake of completeness this is also supported: