tc39 / proposal-optional-chaining

https://tc39.github.io/proposal-optional-chaining/
4.94k stars 75 forks source link

`==` is bad style #144

Closed Some-IOI-Sixer closed 3 years ago

Some-IOI-Sixer commented 3 years ago

Hi,

My colleague let me know that == is bad style. Word is, all the best linter rules prohibit it.

I cannot say he is wrong; but it's confusing when source documents such as this proposal use this frowned-upon syntactical hackery.

/s

dantman commented 3 years ago

a == null is a common exception to that rule. == is bad practice because of problems caused by the loose type conversion.

a == null has a well defined and useful meaning, it is equivalent to a === null || a === undefined so it's a commonly used exception to the rule when you want to check if something is nullish.

e.g. a == null ? b : a is equivalent to a ?? b.

claudepache commented 3 years ago

Whether it is bad style is a matter of opinion.

Although this repo is not supposed to serve as documentation for people that don’t necessarily know the == null trick, while writing the explainer, I have been careful enough to complement occurrences of == null with a comment saying explicitly “null or undefined”, or, more colloquially, “nullish”.