r/learnjavascript • • Aug 16 '26

Strange result: null vs 0

Strange result: null vs 0

An incomparable undefined

Hi, can anyone explain this? I read the explanation, but I still don't understand it. I'm trying to understand it without using AI

4 Upvotes

27 comments sorted by

View all comments

Show parent comment

2

u/defaultguy_001 Aug 16 '26

Just use this ESlint rule and you'll face no issues like above.

rules: {
// Enforces === and !== everywhere 
"eqeqeq": ["error", "always"],

// Highly recommended companion rule
"no-eq-null": "error"
}

1

u/BenchEmbarrassed7316 Aug 16 '26

ESLint Playground

I added both rules you suggested.

It doesn't catch these errors. In the case where a variable is used instead of a literal it doesn't catch any errors (because that's what you need types for).

If I did something wrong - please correct me.

1

u/defaultguy_001 Aug 16 '26

Do u now see the errors?

playground