+ 1

Can u explain == and ===?

15th Nov 2016, 12:21 PM
Athul
Athul - avatar
4 Answers
+ 7
== is called soft while === is considered as hard comparisson operator using=== is considered as best practice, at least that's what I read in the JS Ninja book.
21st Feb 2017, 3:21 AM
Mirza Sisic
Mirza Sisic - avatar
+ 5
So, = means "Assign this value to this variable". It sets values. On the other hand, == or === mean "Check if this value is eaual to this variable". It's checking for something, or asking a question. It's more often than not in if statements. Like so: if (name === "Athul") { console.log("Hello, Athul!") }
15th Nov 2016, 12:28 PM
Keto Z
Keto Z - avatar
0
Beside ==, === also compares the data types. JavaScript is intelligent and in the case of 1 == '1' it converts the string '1' into a number. But with '===' you tell JavaScript to be more precise and you ask for an 'absolute equality'. Hope it was useful!
6th Dec 2016, 12:04 AM
Cristian-Alexandru Ioan
Cristian-Alexandru Ioan - avatar