Home > Web Front-end > JS Tutorial > body text

Introduction to the difference between undefined and null in js_Basic knowledge

WBOY
Release: 2016-05-16 17:36:45
Original
1159 people have browsed it

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.                             

In

s, undefined and null are equal if == is used, and unequal if === is used.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!