Difference between =, == , and ===
Feb 9, 2022
one extra ‘=’ hit and you’re coding something totally different
- = is used for assigning values to a variable in JavaScript.
- == is used for comparison between two variables irrespective of the data type of variable.
- === is used for comparison between two variables but this will check strict type, which means it will check datatype and compare two values.
Examples
= examples
var a = 4;
//assigning that a is 4
== examples
var a = 4;
console.log(a == "4")//returns TRUE
//- as it compares the operands* and not the data type
=== examples
var a = 4;
console.log(a === "4")//returns FALSE
//- as it compares the operands AND the data type
*Check this page to find “operands”:
A resource I found that helps a lot a lot:
from https://www.guru99.com/difference-equality-strict-operator-javascript.html