7wp
7wp

Reputation: 12674

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?

Upvotes: 30

Views: 21443

Answers (3)

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827256

Yes, !== is the strict version of the != operator, and 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

Upvotes: 11

BalusC
BalusC

Reputation: 1108672

I was about to post this W3Schools page, but funnily enough it didn't contain this operator!

At least, the !== is indeed the inverse of === which tests the equality of both type and value.

Upvotes: 6

Joey
Joey

Reputation: 354416

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

Upvotes: 38

Related Questions