When a variable is declared but not assigned a value and a variable is not declared, it is undefined type data
JS variables must also be declared before use
If an undefined variable x is used, an error will be reported.
How to determine whether a variable is available:
The first method:
if(typeof x=='undefined')
var n=100;
n=new Date();
n= null;
null represents a clear known value, which is an empty object
Second method:
if(typeof(y)!='undefined' && v!=null)//You can also determine whether a variable is available
Third method:
var v;
if(v)
{//v will be converted to Boolean type and then judged.
alert('available');
}
else{
alert('unavailable');
}
We rarely use the first and second methods, and usually use the third.
Ins, undefined and null are equal if == is used, and unequal if === is used.