What's difference of equal operator to strict equal operator?

Hello, I have a simple question with equal operator(==) and strict equal oprator(===).

It’s about Javascript exercise on conditional. Here’s the link

The codecademy program said I was wrong when I used just equal operator, even though the result was same as using strict equal operator. (Both worked and printed the same result.)

So, I’m eager to know how those two operator actually works behind the screen. Thank you in advance!

let favoritePhrase = 'Love That!';

favoritePhrase === 'Love That!' // favoritePhase == 'Love That' prints the same result. 
? console.log('I love that!')
: console.log("I don't love that!");```

=== is exactly equal. ‘0’ as a string is not the same as 0 as a string. So it’s strictly equal, as you say.
== is less strict, and will interpret some things by changing the data type to be the same. So it will change ‘12’ as a string to 12 as a number then try to equate them.

1 Like

So I guess I have to learn how exactly comparision works inside of the system. Thanks for replying!

1 Like