tc39/proposal-optional-chaining

`==` is bad style

Some-IOI-Sixer opened this issue · 2 comments

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

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.

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