0

What does means by following expression please give any reference for expression like that in javascript

var variable= somevalue!== undefined; 

Thanks Vishal

Vishal Thoriya
  • 283
  • 5
  • 19
  • I believe the point of your question is the meaning of the `!==` operator. That's used for explicit comparitons. You may search for [other related questions here in SO, like this](http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons). – Geeky Guy Jan 23 '14 at 12:37

3 Answers3

2

!== is the exact mismatch comparator (maybe not the proper name).

basically 1 != "1" evaluates as false, but 1 !== "1" evaluates as true.

In the case above, if somevalue is anything other than undefined variable will be true.

ChrisIPowell
  • 494
  • 2
  • 6
1

This is assigning the variable variable a boolean value based on the outcome of comparing the someValue variable to a value of undefined.

variable will end being either true or false depending if someValue is currently defined in the code.

The !== operator means strict does not equal, as in it doesn't equal in type or in value.

Assigning a boolean like this would be good if you need to reuse the value of the comparison. Instead of doing the comparison multiple times over in different if statements, you can assign a single variable, do the comparison once, and then use the boolean value multiple times in the code.

You can read more about JavaScript's comparison operators on MDN

SomeShinyObject
  • 7,581
  • 6
  • 39
  • 59
1

The expression somevalue!== undefined will return either true or false.

The variable variable will then be set to that true/false value.

Spudley
  • 166,037
  • 39
  • 233
  • 307