0

I'm new to Java Script What is the exact difference between (== Vs ===, != Vs !==, etc) in JavaScript? Have read some articles and wanted to be more clear on this. Thanks in advance.

2
  • youtube.com/watch?v=O24XMM1PTqQ Commented Apr 14, 2014 at 21:14
  • if a function returns multiple values that are equivalent to false like 0, '0' or false (for example 0 means no result and false and error) and you want them to be treated the same then you can use == but if you want them to be treated differently then you have to use ===. Commented Nov 13, 2015 at 10:39

1 Answer 1

3

The == operator means equality after type conversion

1 == '1';  // true
1 == 1;    // true

The === operator means equality without any conversion

1 === '1'; // false
1 === 1;   // true
Sign up to request clarification or add additional context in comments.

3 Comments

Ah so that's why ",,," == new Array(4); returns true... :/
!= and !== do the same thing but consider inequality of values converted and of types.
'==' is used to compare only values. '===' is used to compare both value and type of the variable being compared. Both return a boolean value as result based on the comparison.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.