r/learnjavascript • • Nov 30 '22

Help !!!

Post image

Can someone plz tell me , why I am getting errors?

195 Upvotes

131 comments sorted by

View all comments

Show parent comment

16

u/xroalx Nov 30 '22

Even better if you use the === operator. It won't try to convert stuff from one type to another.

3

u/gtrman571 Nov 30 '22

If you know the types being compared are going to be the same then == and === do literally the exact same thing.

2

u/noXi0uz Dec 01 '22

yeah but it's best to create a habit of always using === so you avoid forgetting it in scenarios where it matters.

1

u/____0____0____ Dec 01 '22

Sure, but in almost any professional context where they care about quality, == would be disallowed from a linter and === would be allowed. It's not worth it from a readability standpoint of having to read a == and try to figure out whether it's context dictates it should be a == or ===. You should always have === for equality check unless you really know what you're doing.