javascript - Check if variable is not undefined because it's === true or has a value assigned -
Sometimes I see that it is normal to do this on Status: Live demo: In this case 1) How can I check if 2) Is it possible to check it without using an additional 3) What is the better way to test it? In both the situations described above, (at number 1) is found in the PS I'm just using You have three options for a single parallelism test: Critical equality Loose similarity Any true / incorrect value If you are trying to tell the difference between If you just want to know that there is a value in the variable (such as is not undefined), then you can use strict similarity probes and the actual javascript For whether the
variable is not
undefined because it is assigned a value :
if (variable) ) {/ * Not undefined However, I was asking myself how can I check that if
variable is not
undefined is not in the following /
$ (f Urection () {var person = create ('John'); var isMarried = person hemorrhoid; console.log ('smile is:' + smile is); if (has been) {console.log ('do something!' )}}}); Create function (name) {var person = {}; person. Name = name; Person.isMarried = getRandom (); Return person; }; Function getRandom () {var arr = [true, 'no', undefined]; Var Rand = ARR [Math. Floor (Math.Random * * arr.length); Return Rand;};
Harried Variables < Code> true ,
'no' , or
undefined .
So, my questions are ...
harried variable no
undefined because it is
===
true (equals true) or because its value was assigned is? (This is the last one when
happens === 'no' ).
if statement or condition?
if statement in the browser
console Check Output from:
has been hacked: Do something true! Surprised: Undefined is Elite: Do not Do Something!
jQuery for testing, this question is not related to that framework! Thank you.
if (person.isMarried === true) or
if (person.isMarried! == undefined) . Check whether any variable is clearly something (without any kind of conversion allowed).
if type (person.isMarried == true) type conversions are allowed.
if (person.ismaried) . If there is a true value in the
person.nosigned , then it will be deemed to be. Even
"no" will be a true value.
"no" ,
false and
Undefined , you must use more than one comparison because these are different values of different types.
undefined value You can compare:
if (person.isMarried! == undefined) {// There is some value in person. Although merged, it can be anything other than an uncertain value}
Comments
Post a Comment