DEV Community

professional writer
professional writer

Posted on

Difference between “ == “ and “ === “ operators

Both operate on comparisons. The distinction between the two operators is that while "==" compares values, " === compares both values and types.

read also : A powerpoint presentation's encryption: adding it

Example:

var x = 2;
var y = "2";
(x == y)  // Returns true since the value of both x and y is the same
(x === y) // Returns false since the typeof x is "number" and typeof y is "string"
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Nice, simplified explanation. However, comparing 'values' is a whole topic in itself 🤓

Collapse
 
stephennn99 profile image
Stephennn99

Great comparison