Interesting Bugs Caught by ESLint’s no-constant-binary-expression

ESLint v8.14.0 introduces the new core rule called no-constant-binary-expression, which has proven to be effective in detecting subtle and interesting bugs. The rule checks for comparisons and logical expressions that always or never result in a specific outcome. Examples of bugs that the rule has found include confusing operator precedence, misunderstanding the use of ?? and ||, expecting objects to be compared by value, expecting empty objects to be nullish or falsy, and typos such as using “=>” instead of “>=” in comparisons. Enabling this rule in projects can help identify and fix these common coding errors.

https://eslint.org/blog/2022/07/interesting-bugs-caught-by-no-constant-binary-expression/

To top