Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JavaScript is != same as !== [duplicate]

Possible Duplicates:
Javascript === vs == : Does it matter which “equal” operator I use?
Javascript operator !==

Look at this commit

Is != same as !== in JavaScript?

like image 743
Roger Avatar asked Dec 22 '09 12:12

Roger


People also ask

What is != and !== In JavaScript?

The strict inequality operator ( !== ) checks whether its two operands are not equal, returning a Boolean result. Unlike the inequality operator, the strict inequality operator always considers operands of different types to be different.

Is != The same as ==?

Equality operators: == and != The result type for these operators is bool . The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false . The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .

Should I use != Or !==?

Inequality Operators: !=!= : Converts values if variables are different types before checking for inequality. !== : Checks both type and value for the two variables being compared.

What is === called in JavaScript?

The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.


1 Answers

They are subtly not the same.

!= checks the value
!== checks the value and type

'1' != 1   // false (these two are the same) '1' !== 1 // true (these two are **not** the same). 

In the previous example. The first half of the expression is a string, the second half is an integer.

like image 174
Amadiere Avatar answered Sep 21 '22 12:09

Amadiere