What is the difference between = and ===?

what is difference between mood===‘sleepy’ and mood=‘sleepy’?

mood===‘sleepy’ => comparison

mood=‘sleepy’ => assignment

17 Likes

mood = 'sleepy' is assigning the value ‘sleepy’ to the variable mood.
mood === 'sleepy' is testing whether the variable mood has been assigned the value ‘sleepy’.

6 Likes

is there operator ‘==’ in JS? and if so what’s the difference to the ‘===’?

3 Likes

== looks at the value irrelevant of its type.
=== also checks if the type is the same.

Example:

2 == '2' // true, number and string have the same value so they are equal.
2 === '2' // false, number and string are not of the same type.
14 Likes

let money = 20000;
if(money === 20000){
console.log(‘I AM RICH’);
}

= IS USED TO ASSINGN A VALUE WHILE === IS USED IN CHECKING A VALUE…EXAMPLE;
THE = ASSIGNS THE VARIABLE MONEY A VALUE OF 20000…WHILE IN THE SECOND WE USED THE === TO CHECK IF THE VALUE OF MONEY IS 20000 SO;

= IS USED IN ASSIGNING VALUES!
=== IS USED IN CHECKING VALUES!

2 Likes