Different between == and === in JavaScript examples

This post covers an examples and notes about comparison of double equal signs(==) and thriple equal signs(===) operators in JavaScript.

First what does equal signs about?

Both operators are used to compare different values.

== is called equality operator, which applies type coercion, what doe type coercion, It convert the values before comparison

m==n returns true if m and n are same values and types, else false.

=== is called identity operators, which not applies type coercion, not converting the values before conversion.

m===n returns true if m and n are same values for strings and same reference for objects, else false.

== and === operator Examples

Here are some examples of double equal and three equal operator examples

5=="5"  - true
5==="5" - false

'0' == undefined // true
'0' === undefined // false

null == undefined // true
null === undefined // false

difference between == vs === operators

Both operators are applied two operands or variables

== operator   === operators  
Called Comparison operator Strict comparison operator
compared two operands or variables, data type is ignored compared two operands or variables and data type

|Returns true, if values are equal,false not equal| Returns true, if values and types are equal,false both not equal| |duration|  time in milliseconds shown before disappear from the page| |type coercion before comparison| type coercion ignored before comparison|

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.