Whats the different between two (`==`) and three (`===`) equal signs?

Why are there three === instead of two?

3 equals signs is known as Identity / strict equality, meaning that the data types also must be equal:

console.log(1 == true) // output: true
console.log(1 === true) // output: false

For anyone still interested - there is a great explanation with examples here


what about a single (=) equals? In this module 7 (number) does seem to = 7 (number) and also “7” (string). I understand why you would use triple equals, but why NOT use single as opposed to double?

1 Like

= is assignment.
== check if values are equal:

3 == "3" // true

=== also check if the data type matches:

3 === "3" // false

Okay, I see. I wasn’t actually comparing 7 (number) to 7(number) it was redefining the variable, and in this case they did just so happen to actually be equal. When I reran the premise just now I found that the following IF evaluated as true (or perhaps more technically, the variable sven had a truthy value?).

let sven = 7;
if (sven='taco') {

The output to the console was ‘taco’.

So now this is clear to me. Thanks for the feedback!

1 Like

Thanks for sharing this article!

1 Like

The “===” stands for “equal to” whiles the “==” stands for equivalence.

1 Like

No caso desse exemplo => ‘apples’ === ‘oranges’ // false qual foi o criterio para resultado ser falso?como se chegou a esse resultado ok ambos sao strings e ‘apples’ != ‘orange’

thank you!!! <3 <3 <3

thank you so much!!!

Thank you! This answer is very clear!

== is an Equality operator and performs abstract comparison by doing type coercion before comparing i.e Converts the variable to same datatype then compares
=== is an Identity operator and performs strict comparison i.e Does not convert to same data type.

This code compares two values with different datatypes i.e string and number
Expect true using == and false ===

let a = 2020
let b = "2020"
//This result wont show up because the values are not of same type
if (a === b) {
    console.log(`strict a: ${a}`)
    console.log(`strict b: ${b}`)
//This result will show up because b will be converted to number before comparison. 
if (a == b) {
    console.log(`abstract a: ${a}`)
    console.log(`abstract b: ${b}`)
1 Like