Not so Weird Parts of Javascript - Part 1

·

1 min read

Do you know, In Javascript 1 == '1' will give true as output whereas 1 === '1' gives false?

Well, the reason behind this is,
The ==(double equals) does type conversion first followed by a comparison of values, whereas ===(triple equals) does the same comparison without type conversion (ie both data type & values are compared)

But what's the use case of triple equals?

Because JavaScript is a weakly typed language, sometimes you can have unexpected type conversions. This happens implicitly when you try to use some operators between data of different types. Then instead of getting an error, JavaScript tries to "help" you, which unknowingly might give you an undesired output!

That's not all folks, if you liked this article, do like, share, and subscribe as I plan to bring more such content in near future.

console.log("See you soon");