user469910
user469910

Reputation:

what does the !== operator do in javascript?

if (description !== undefined)

i found this in nerd dinner tutorial.

Upvotes: 2

Views: 189

Answers (3)

Subhash Dike
Subhash Dike

Reputation: 1891

This is the strict not equal operator and only returns a value of true if both the operands are not equal and/or not of the same type. The following examples return a Boolean true:

a !== b 
a !== "2" 
4 !== '4' 

For more operator information refer here Dev Guru Forum

Upvotes: 2

Fredrik Widerberg
Fredrik Widerberg

Reputation: 3108

This is the strict not equal operator and only returns a value of true if both the operands are not equal and/or not of the same type.

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382676

It is identity operator that not only checks for value but also type.

Example:

if (4 === 4)  // both type and value are same
{
  // true
}

but

if (4 == "4")  // value is same but type is different but == used
{
  // true
}

and

if (4 === "4")  // value is same but type is different but === used
{
  // false
}

You should use === or !== once you are sure about both value and type.

Upvotes: 4

Related Questions