JavaScript? ??? ??? ?? ??
??? ??? ?? ??:
typeof()
typeof()? ???? ??? ??? ???? ? ????.
typeof() ??? ??? ?? ??????.
typeof()? ?? ????? "???", "??", "??", "???? ??", "??", "??" ? ?? ??? ????.
???: null, object ? array? ?? "object"? ?????.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var x1 = "abc"; //string var x2 = 110; //number var x3 = true; //boolean var x4; //undefined var x5 = null; //object //使用typeof()判斷變量的數(shù)據(jù)類(lèi)型 var result = typeof(x5); //輸出變量的類(lèi)型和結(jié)果 document.write(x5+"的數(shù)據(jù)類(lèi)型為:"+result); </script> </head> <body> </body> </html>
??: ?? ?? ??? ??? ??? ??? ? ? ????
????? ?? ? ?? ??? ?? ?? ??
parseInt() ??? ??, ?? ??
??: ????? ???? ????? ??? ?????. ??? ?? ???? ???? ??? ???? ??? ?????.
??: ? ?? ??? ??? ?? ?? ?? ???? NaN? ?????.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> document.write(parseInt("500eps")+"<br/>"); document.write(parseInt("500.88")+"<br/>"); document.write(parseInt("a120px")+"<br/>"); </script> </head> <body> </body> </html>
parseFloat() ??? ??, ?? ??
??: ????? ?? ??? ?? ???? ?? ?? ???? ????? ?? ??? ??? ?????. , ??? ???? ??? ?????.
??: ? ?? ??? ?? ???? ?? ?? ?? ???? NaN? ?????.
????