What does means by following expression please give any reference for expression like that in javascript
var variable= somevalue!== undefined;
Thanks Vishal
What does means by following expression please give any reference for expression like that in javascript
var variable= somevalue!== undefined;
Thanks Vishal
!== 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.
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
The expression somevalue!== undefined
will return either true
or false
.
The variable variable
will then be set to that true/false value.