Did you know === also coerces type in JavaScript?

However, unlike ==, === will always return false if the types differ.

That == and === both perform type coercion under the hood in JavaScript is such a fun fact!

Thanks for stopping by and sharing your knowledge with us Clyde Grey!!!

I have written previous about the difference between loose equality and strict equality in JavaScript, but I never realized that === includes a type coercion as well.

It’s right there in the ECMAScript Specification:

Indeed there is a type comparison with ===, and if the types differ the result is always false.

But I had never really thought about it that way!

Of course, it’s just a bit of trivia, and the idea can be a bit confusing for those new to JavaScript, since == compares values after type coercion but === will never return true for values of different types.

Thanks again for sharing!

Image for post
Image for post
Photo by Erol Ahmed on Unsplash

πŸ€“ The physical therapist who writes JavaScript πŸ’ͺ Web Developer 😎 Mentor 🧠 DPT πŸ˜„ SEO Expert 😁 React πŸ˜† Jamstack πŸ’¬ Ask me anything πŸ‘‰ DoctorDerek.com πŸ‘ˆ

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store