Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between != and !== operators in JavaScript?

What is the difference between the !== operator and the != operator in JavaScript? Does it behave similarly to the === operator where it compares both value and type?

like image 926
7wp Avatar asked Dec 11 '09 16:12

7wp


People also ask

Why do we prefer === and !== Over == and != In JavaScript?

The strict equality operator ( === ) behaves identically to the abstract equality operator ( == ) except no type conversion is done, and the types must be the same to be considered equal. The == operator will compare for equality after doing any necessary type conversions.

What are the difference between == === and !=?

The === operator compares operands and returns true if both operands are of same data type and have some value, otherwise, it returns false. The !== operator compares operands and returns true if both operands are of different data types or are of the same data type but have different values.

What is the difference between != and not?

The != operator compares the value or equality of two objects, whereas the Python is not operator checks whether two variables point to the same object in memory.

What is the meaning of != Operator?

The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .


2 Answers

Yes, it's the same operator like ===, just for inequality:

!== - returns true if the two operands are not identical. This operator will not convert the operands types, and only returns false if they are the same type and value. —Wikibooks

like image 108
Joey Avatar answered Sep 21 '22 13:09

Joey


Yes, !== is the strict version of the != operator, no type coercion is done if the operands are of different type:

0 != ''            // false, type coercion made 0 != '0'           // false false != '0'       // false  0 !== ''           // true, no type coercion 0 !== '0'          // true false !== '0'      // true 
like image 30
Christian C. Salvadó Avatar answered Sep 19 '22 13:09

Christian C. Salvadó