StudioWeb is the most advanced code training platform out there today. Since 2011, StudioWeb has taught well over 1 million students real-world coding and programming. We currently offer career oriented courses in the following in demand languages:
When you use “=” you are assigning the value of something like for example a variable to something else.
let var1 = 'hello'
var1 = 'world'
//outputs 'world', because we reassigned the value from 'hello' to 'world'
Now == is used to check if two values are the same, but it does not check type, meaning that.
‘1’ is a string, because it’s wrapped in quotes.
1 is a number because it’s an integer and it is not wrapped in quotes.
if we do for example.
‘1’ == 1
//output would be 'true' because the == operator is checking to see if '1' and 1, have the same value which is the number 1, it is not checking if '1' is a number, or if 1 is a string it's checking if '1' and 1 have the same value which is the number 1.
To check for type we use the strict equality operator or ===
So in the previous example, == checks for value not for type, === checks for value AND type.
Which means that
‘1’ === 1
would return “false” because ‘1’ is not a number it’s a string, and 1 is a number not a string.
1 === 1 returns ‘true’
‘1’ === ‘1’ returns ‘true’