Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Possible Duplicates:
Difference between == and === in JavaScript
Javascript === vs == : Does it matter which “equal” operator I use?

What's the difference between == and ===? Also between !== and !==?

like image 571
jslearner Avatar asked Mar 16 '11 09:03

jslearner


People also ask

What is the difference between == & === in JS?

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 out of == or === is faster?

Equality operator == converts the data type temporarily to see if its value is equal to the other operand, whereas === (the identity operator) doesn't need to do any type casting and thus less work is done, which makes it faster than ==.


1 Answers

There are lots of answers to this question on Stackoverflow already.

Short:

== only compares values

=== compares values + type


var check1 = '10',
    check2 = 10;

check1 == check2 // true
check1 === check2 // false
like image 94
jAndy Avatar answered Sep 30 '22 17:09

jAndy