<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>变量</title> </head> <body> <script> alert("变量练习"); /** * document.write(num+"<br>");输出到页面上 */ //定义number类型 var a = 123; document.write(a + "<br>"); var b = 1.2; document.write(b + "<br>"); var c = NaN; document.write(c); //定义string类型 var str = "abc"; var str2 = 'edf'; document.write(str + "<br>"); document.write(str2 + "<br>"); //定义boolean var flag = true; document.write(flag + "<br>"); // 定义null,undefined var obj = null; var obj2 = undefined; var obj3; document.write(obj + "<br>"); document.write(obj2 + "<br>"); document.write(obj3 + "<br>"); </script> </body> </html>