+ 4

What is difference of == and ===?

I'm pretty expert on JavaScript, but still I haven't understood what's the difference from == to === in conditions. Can someone explain me please?

8th Apr 2022, 10:00 PM
Gabriele Giambrone
Gabriele Giambrone - avatar
6 Answers
+ 7
==is used to only compare values on the other hand === is also used to compare data types đŸ‘đŸ»
9th Apr 2022, 11:43 AM
AARAV PANDEY
AARAV PANDEY - avatar
+ 6
console.log("100" == 100, "100" === 100, 100 === 100) // true false true == compare only value === compares value & type data
8th Apr 2022, 10:13 PM
Ferdiansyah
Ferdiansyah - avatar
+ 5
== checks if the value is equals so 4 == "4" is true because one side is converted to the other type (in JavaScript this is done by Abstract Equality Comparison Algorithm). This leads also to weird results like NaN == NaN is false. === checks also if the type is the same so 4 === 4 is true and 4 === "4" is false. The same rules are there for != and !==. There are languages who know === like JavaScript and PHP but the most languages don't know ===
9th Apr 2022, 7:33 AM
Joël Egger
Joël Egger - avatar
+ 4
== just compares values while === strictly compare values with types including.... "1" == 1 returns true "1" === 1 returns false
8th Apr 2022, 10:08 PM
Jayakrishna 🇼🇳
+ 1
== is used to compare values, === is used to compare values and their data types.
10th Apr 2022, 4:40 PM
Mohamed Belgazem
Mohamed Belgazem - avatar
0
== compares only values. === compares values and types in same time For exemple: ('33' == 33 ) is true But ('33' === 33) is false cuz '33' is a string but 33 is a number
10th Apr 2022, 9:38 PM
Mohammed RIFAI
Mohammed RIFAI - avatar