JavaScript ??, null, ? ???? ??
typeof ???
typeof ???? ???? ??? ??? ??? ??? ? ????.
typeof? ????? ???? ???? ?? ?? "???? ??"???.
????? ?????. typeof(x) = "number"
String typeof(x) = "string"
Boolean ? typeof(x) = "boolean"
Object, array and null typeof(x) = "object"
Function typeof(x) = "function"
typeof ???? ??? ???? ??? ??? ???? ? ???? ??? ?????.
??? ???? "??", "???", "??", "??", "??" ? "???? ??"???.
?:
alert(typeof (123));//typeof(123)? "??"? ?????.
alert(typeof ("123"));//typeof("123")? "???"? ?????
typeof ?? ???? ??? ??? ???? ???? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php.cn</title> </head> <body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = typeof "john" + "<br>" + typeof 3.14 + "<br>" + typeof false + "<br>" + typeof [1,2,3,4] + "<br>" + typeof {name:'john', age:34}; </script> </body> </html>
Null
Null ? ??? ??? ???? ?? ??? ?????. ?? ??, ?? ??? ?? ??? ??? ?? ? JavaScript? ???? ??? ?? ?? ??? ?? ???? ?? ??? null???.
null ??? ????? ??? ??? null? ???? ???.
if( x == null ) { ... }
? ??? ?? ??? ???? , ?? ? ?? ??? ???? ??? ??? null ?? ???? ??? ??? ?? ? ????.
Undefine
??? ??? ? ??? ??? ?? ??? ?? ??? ???? ?? ?????. ???? ?? ??? ?? ?? ???? ????? ?? ?? ?? ??? ???? ?? ???? ????? ???? ?? ??? ???? ???.
if( x == undefine ) { ... }
???? ??? Null? ???
???? ?? ???? ???? ?? ?? ??? ????. ??? ??? ????? ?? ?? ??? ???? ???? ????.
Null ???? null ?? ??? ????. Null? ?? ???? ?? ??? ???? ? ?????. ??? ???? ?? ??? ????? ???? ???? ? ?? ?????.
undefine? ??? ???? ???? ?????? ?? ???? ???? ?????(????? ??). ?? ????? ???? ?? ?? ???? ??? ?? ??? ???? ???? ?? ?????. ?? ???? ???? ??? ?????.
null? "? ??"? ???? ????.
Javascript? ???? ?? ??? ???? ???? ???? ?????.
Javascript? ??? null? ???? ????. ?? ?????? var? ??? ??? ?? ??? ???? ? ?????.
undefine? ??? JSON? ???? null?
null ?????. ;
??? ?? ?? ?????.
??? ?? ?????(Boolean(undefine) ->// false, Boolean(null) ->// false);
??? ?? ??? ??? ? ????. ???? ???? ?????. typeof ?? === "undefine";
? ???? ??? null?? ??? ? ????. ?? === null;
?? ??? ??? ? ?????(null==???? ?? ->// true), ?? ??? ??? ? ???? ????(null===undefine->// false)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php.cn</title> </head> <body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = typeof undefined + "<br>" + typeof null + "<br>" + (null === undefined) + "<br>" + (null == undefined); </script> </body> </html>