Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between == and === in JavaScript [duplicate]

What is the difference between == and === in JavaScript? I have also seen != and !== operators. Are there more such operators?

like image 678
Shiva Avatar asked Feb 07 '09 11:02

Shiva


People also ask

What is the difference between == vs === in JavaScript?

The main difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.

What is the difference between double == and triple === equals?

Double Equals ( == ) checks for value equality only. It inherently does type coercion. This means that before checking the values, it converts the types of the variables to match each other. On the other hand, Triple Equals ( === ) does not perform type coercion.

Which is faster == or === in JavaScript?

So === faster than == in Javascript === compares if the values and the types are the same. == compares if the values are the same, but it also does type conversions in the comparison. Those type conversions make == slower than ===.

Which of the following is a difference between == and === in JavaScript select the most accurate answer?

Since == doesn't bother with types, that returns true. However, if you want strict type checking, you'd use === because that returns true only if the it's of the same type, and is the same value. positions. Two numbers are strictly equal when they are numerically equal (have the same number value).


1 Answers

Take a look here: http://longgoldenears.blogspot.com/2007/09/triple-equals-in-javascript.html

The 3 equal signs mean "equality without type coercion". Using the triple equals, the values must be equal in type as well.

0 == false   // true 0 === false  // false, because they are of a different type 1 == "1"     // true, automatic type conversion for value only 1 === "1"    // false, because they are of a different type null == undefined // true null === undefined // false '0' == false // true '0' === false // false 
like image 161
sdfx Avatar answered Sep 30 '22 16:09

sdfx