how2j.cn


工具版本兼容问题
基本数据类型
undefined,Boolean,Number,String,null

关键字 简介 示例代码
undefined
声明了但未赋值
示例代码
Boolean
布尔
示例代码
Number
数字
示例代码
String
字符串
示例代码
var
动态类型
示例代码
typeof
变量类型判断
示例代码
null
空对象/对象不存在
示例代码
示例 1 : 声明了但未赋值   
示例 2 : 布尔   
示例 3 : 数字   
示例 4 : 字符串   
示例 5 : 动态类型   
示例 6 : 变量类型判断   
示例 7 : 空对象/对象不存在   

示例 1 :

声明了但未赋值

当一个变量被声明了,却没有赋值的时候,叫做 undefined
"); window.frames["iframe_show1075"].document.write(decodeHtml($("textarea#stepcodeTextarea1075").val())); window.frames["iframe_show1075"].document.close(); $(window.frames["iframe_show1075"]).load(function(){ $("#iframe_show1075").height($("#iframe_show1075").contents().find("body").height()+showittryitheight); }); $("#iframe_show1075").height($("#iframe_show1075").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<script> var x; //声明了变量x,但是没有赋值 document.write('声明了,但是没有赋值的变量 x: '+x); </script>
<script>
  var x; //声明了变量x,但是没有赋值
  document.write('声明了,但是没有赋值的变量 x: '+x);
</script>
"); window.frames["iframe1075"].document.write(decodeHtml(code1075)); window.frames["iframe1075"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1075"]).load(function(){ $("#iframe1075").height($("#iframe1075").contents().find("body").height()+showittryitheight); }); $("#iframe1075").height($("#iframe1075").contents().find("body").height()+showittryitheight); alreadyWriteCode1075 = code1075; $("#rendering1075").hide(); $("#rendered1075").show(); } var tRereshRetry2DemoPanel1075 = setInterval(rereshRetry2DemoPanel1075,1000); var binded1075 = false; $("textarea#stepcodeTextarea1075").keyup(function(){ if(!binded1075){ $(window).bind('beforeunload',function(){ binded1075 = true; return "xxxx"; }); } var newCode = $(this).val() code1075 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code1075!=newCode){ // window.frames["iframe1075"].document.write("
"); // window.frames["iframe1075"].document.write(decodeHtml($("textarea#stepcodeTextarea1075").val())); // window.frames["iframe1075"].document.close(); // $(window.frames["iframe1075"]).load(function(){ // $("#iframe1075").height($("#iframe1075").contents().find("body").height()+showittryitheight); // }); // code1075 = newCode; // } }); $(".tryButton1075").click(function(){ $("#tryDiv1075").show(); $("#stepcodeTextarea1075").focus(); $("#stepcodeTextarea1075").height(200); $("#iframe1075").height(0); window.frames["iframe1075"].document.write("
"); window.frames["iframe1075"].document.write(decodeHtml($("textarea#stepcodeTextarea1075").val())); window.frames["iframe1075"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1075"]).load(function(){ $("#iframe1075").height($("#iframe1075").contents().find("body").height()+showittryitheight); }); $("#iframe1075").height($("#iframe1075").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor1075.focus(); editor1075.setSize(null, "250"); $("#rendering1075").hide(); $("#rendered1075").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor1075 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1075"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor1075.on("change",function(doc){ if(!binded1075){ $(window).bind('beforeunload',function(){ binded1075 = true; return "xxxx"; }); } var newCode = doc.getValue(); code1075 = newCode; $("textarea#stepcodeTextarea1075").val(newCode); if(alreadyWriteCode1075!=code1075){ lastModifedTime1075 = new Date().getTime(); $("#rendering1075").show(); $("#rendered1075").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor1075 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor1075.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv1075").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 2 :

布尔

Boolean变量有两种值,分别是true或者false
"); window.frames["iframe_show1076"].document.write(decodeHtml($("textarea#stepcodeTextarea1076").val())); window.frames["iframe_show1076"].document.close(); $(window.frames["iframe_show1076"]).load(function(){ $("#iframe_show1076").height($("#iframe_show1076").contents().find("body").height()+showittryitheight); }); $("#iframe_show1076").height($("#iframe_show1076").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<script> var x=true; var y=false; document.write("布尔值:"+x); document.write("<br>"); document.write("布尔值:"+y); </script>
<script>
  var x=true;
  var y=false;
  document.write("布尔值:"+x);
  document.write("<br>");
  document.write("布尔值:"+y);
</script>
"); window.frames["iframe1076"].document.write(decodeHtml(code1076)); window.frames["iframe1076"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1076"]).load(function(){ $("#iframe1076").height($("#iframe1076").contents().find("body").height()+showittryitheight); }); $("#iframe1076").height($("#iframe1076").contents().find("body").height()+showittryitheight); alreadyWriteCode1076 = code1076; $("#rendering1076").hide(); $("#rendered1076").show(); } var tRereshRetry2DemoPanel1076 = setInterval(rereshRetry2DemoPanel1076,1000); var binded1076 = false; $("textarea#stepcodeTextarea1076").keyup(function(){ if(!binded1076){ $(window).bind('beforeunload',function(){ binded1076 = true; return "xxxx"; }); } var newCode = $(this).val() code1076 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code1076!=newCode){ // window.frames["iframe1076"].document.write("
"); // window.frames["iframe1076"].document.write(decodeHtml($("textarea#stepcodeTextarea1076").val())); // window.frames["iframe1076"].document.close(); // $(window.frames["iframe1076"]).load(function(){ // $("#iframe1076").height($("#iframe1076").contents().find("body").height()+showittryitheight); // }); // code1076 = newCode; // } }); $(".tryButton1076").click(function(){ $("#tryDiv1076").show(); $("#stepcodeTextarea1076").focus(); $("#stepcodeTextarea1076").height(200); $("#iframe1076").height(0); window.frames["iframe1076"].document.write("
"); window.frames["iframe1076"].document.write(decodeHtml($("textarea#stepcodeTextarea1076").val())); window.frames["iframe1076"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1076"]).load(function(){ $("#iframe1076").height($("#iframe1076").contents().find("body").height()+showittryitheight); }); $("#iframe1076").height($("#iframe1076").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor1076.focus(); editor1076.setSize(null, "250"); $("#rendering1076").hide(); $("#rendered1076").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor1076 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1076"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor1076.on("change",function(doc){ if(!binded1076){ $(window).bind('beforeunload',function(){ binded1076 = true; return "xxxx"; }); } var newCode = doc.getValue(); code1076 = newCode; $("textarea#stepcodeTextarea1076").val(newCode); if(alreadyWriteCode1076!=code1076){ lastModifedTime1076 = new Date().getTime(); $("#rendering1076").show(); $("#rendered1076").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor1076 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor1076.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv1076").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 3 :

数字

javascript中的Number可以表示十进制,八进制,十六进制整数,浮点数,科学记数法
"); window.frames["iframe_show1077"].document.write(decodeHtml($("textarea#stepcodeTextarea1077").val())); window.frames["iframe_show1077"].document.close(); $(window.frames["iframe_show1077"]).load(function(){ $("#iframe_show1077").height($("#iframe_show1077").contents().find("body").height()+showittryitheight); }); $("#iframe_show1077").height($("#iframe_show1077").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<script> var a=10; //十进制 var b=012;//第一位是0,表示八进制 var c=0xA;//0x开头表示十六进制 var d=3.14;//有小数点表示浮点数 var e=3.14e2;//使用e的幂表示科学计数法 document.write("十进制 10 的值: "+a); document.write("<br>"); document.write("八进制 012 的值: "+b); document.write("<br>"); document.write("十六进制 0xA 的值: "+c); document.write("<br>"); document.write("浮点数 3.14 的值: "+d); document.write("<br>"); document.write("科学记数法 3.14e2 的值: "+e); document.write("<br>"); </script>
<script>
  var a=10; //十进制
  var b=012;//第一位是0,表示八进制
  var c=0xA;//0x开头表示十六进制
  var d=3.14;//有小数点表示浮点数
  var e=3.14e2;//使用e的幂表示科学计数法
  document.write("十进制 10 的值: "+a);
  document.write("<br>");
  document.write("八进制 012 的值: "+b);
  document.write("<br>");
  document.write("十六进制 0xA 的值: "+c);
  document.write("<br>");
  document.write("浮点数 3.14 的值: "+d);
  document.write("<br>");
  document.write("科学记数法 3.14e2 的值: "+e);
  document.write("<br>");
</script>
"); window.frames["iframe1077"].document.write(decodeHtml(code1077)); window.frames["iframe1077"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1077"]).load(function(){ $("#iframe1077").height($("#iframe1077").contents().find("body").height()+showittryitheight); }); $("#iframe1077").height($("#iframe1077").contents().find("body").height()+showittryitheight); alreadyWriteCode1077 = code1077; $("#rendering1077").hide(); $("#rendered1077").show(); } var tRereshRetry2DemoPanel1077 = setInterval(rereshRetry2DemoPanel1077,1000); var binded1077 = false; $("textarea#stepcodeTextarea1077").keyup(function(){ if(!binded1077){ $(window).bind('beforeunload',function(){ binded1077 = true; return "xxxx"; }); } var newCode = $(this).val() code1077 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code1077!=newCode){ // window.frames["iframe1077"].document.write("
"); // window.frames["iframe1077"].document.write(decodeHtml($("textarea#stepcodeTextarea1077").val())); // window.frames["iframe1077"].document.close(); // $(window.frames["iframe1077"]).load(function(){ // $("#iframe1077").height($("#iframe1077").contents().find("body").height()+showittryitheight); // }); // code1077 = newCode; // } }); $(".tryButton1077").click(function(){ $("#tryDiv1077").show(); $("#stepcodeTextarea1077").focus(); $("#stepcodeTextarea1077").height(200); $("#iframe1077").height(0); window.frames["iframe1077"].document.write("
"); window.frames["iframe1077"].document.write(decodeHtml($("textarea#stepcodeTextarea1077").val())); window.frames["iframe1077"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1077"]).load(function(){ $("#iframe1077").height($("#iframe1077").contents().find("body").height()+showittryitheight); }); $("#iframe1077").height($("#iframe1077").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor1077.focus(); editor1077.setSize(null, "250"); $("#rendering1077").hide(); $("#rendered1077").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor1077 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1077"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor1077.on("change",function(doc){ if(!binded1077){ $(window).bind('beforeunload',function(){ binded1077 = true; return "xxxx"; }); } var newCode = doc.getValue(); code1077 = newCode; $("textarea#stepcodeTextarea1077").val(newCode); if(alreadyWriteCode1077!=code1077){ lastModifedTime1077 = new Date().getTime(); $("#rendering1077").show(); $("#rendered1077").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor1077 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor1077.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv1077").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 4 :

字符串

与java不同的是,javascript中没有字符的概念,只有字符串,所以单引号和双引号,都用来表示字符串。
"); window.frames["iframe_show1078"].document.write(decodeHtml($("textarea#stepcodeTextarea1078").val())); window.frames["iframe_show1078"].document.close(); $(window.frames["iframe_show1078"]).load(function(){ $("#iframe_show1078").height($("#iframe_show1078").contents().find("body").height()+showittryitheight); }); $("#iframe_show1078").height($("#iframe_show1078").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<script> var x='hello '; //单引号 var y="javascript"; //双引号 document.write("单引号的字符串:"+x); document.write("<br>"); document.write("双引号的字符串:"+y); </script>
<script>
  var x='hello '; //单引号
  var y="javascript"; //双引号
  document.write("单引号的字符串:"+x);
  document.write("<br>");
  document.write("双引号的字符串:"+y);
</script>
"); window.frames["iframe1078"].document.write(decodeHtml(code1078)); window.frames["iframe1078"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1078"]).load(function(){ $("#iframe1078").height($("#iframe1078").contents().find("body").height()+showittryitheight); }); $("#iframe1078").height($("#iframe1078").contents().find("body").height()+showittryitheight); alreadyWriteCode1078 = code1078; $("#rendering1078").hide(); $("#rendered1078").show(); } var tRereshRetry2DemoPanel1078 = setInterval(rereshRetry2DemoPanel1078,1000); var binded1078 = false; $("textarea#stepcodeTextarea1078").keyup(function(){ if(!binded1078){ $(window).bind('beforeunload',function(){ binded1078 = true; return "xxxx"; }); } var newCode = $(this).val() code1078 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code1078!=newCode){ // window.frames["iframe1078"].document.write("
"); // window.frames["iframe1078"].document.write(decodeHtml($("textarea#stepcodeTextarea1078").val())); // window.frames["iframe1078"].document.close(); // $(window.frames["iframe1078"]).load(function(){ // $("#iframe1078").height($("#iframe1078").contents().find("body").height()+showittryitheight); // }); // code1078 = newCode; // } }); $(".tryButton1078").click(function(){ $("#tryDiv1078").show(); $("#stepcodeTextarea1078").focus(); $("#stepcodeTextarea1078").height(200); $("#iframe1078").height(0); window.frames["iframe1078"].document.write("
"); window.frames["iframe1078"].document.write(decodeHtml($("textarea#stepcodeTextarea1078").val())); window.frames["iframe1078"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1078"]).load(function(){ $("#iframe1078").height($("#iframe1078").contents().find("body").height()+showittryitheight); }); $("#iframe1078").height($("#iframe1078").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor1078.focus(); editor1078.setSize(null, "250"); $("#rendering1078").hide(); $("#rendered1078").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor1078 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1078"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor1078.on("change",function(doc){ if(!binded1078){ $(window).bind('beforeunload',function(){ binded1078 = true; return "xxxx"; }); } var newCode = doc.getValue(); code1078 = newCode; $("textarea#stepcodeTextarea1078").val(newCode); if(alreadyWriteCode1078!=code1078){ lastModifedTime1078 = new Date().getTime(); $("#rendering1078").show(); $("#rendered1078").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor1078 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor1078.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv1078").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 5 :

动态类型

变量的类型是动态的,当值是整数的时候,就是Number类型,当值是字符串的时候,就是String类型
"); window.frames["iframe_show1079"].document.write(decodeHtml($("textarea#stepcodeTextarea1079").val())); window.frames["iframe_show1079"].document.close(); $(window.frames["iframe_show1079"]).load(function(){ $("#iframe_show1079").height($("#iframe_show1079").contents().find("body").height()+showittryitheight); }); $("#iframe_show1079").height($("#iframe_show1079").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<script> var x=10; //Number类型 document.write("此时 x的值是 "+x+" 类型是数字"); document.write("<br>"); x = "hello javascript"; //String类型 document.write("此时 x的值是 "+x+" 类型是字符串"); </script>
<script>
  var x=10; //Number类型
  document.write("此时 x的值是 "+x+" 类型是数字");
  document.write("<br>");
  x = "hello javascript"; //String类型
  document.write("此时 x的值是 "+x+" 类型是字符串");
</script>
"); window.frames["iframe1079"].document.write(decodeHtml(code1079)); window.frames["iframe1079"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1079"]).load(function(){ $("#iframe1079").height($("#iframe1079").contents().find("body").height()+showittryitheight); }); $("#iframe1079").height($("#iframe1079").contents().find("body").height()+showittryitheight); alreadyWriteCode1079 = code1079; $("#rendering1079").hide(); $("#rendered1079").show(); } var tRereshRetry2DemoPanel1079 = setInterval(rereshRetry2DemoPanel1079,1000); var binded1079 = false; $("textarea#stepcodeTextarea1079").keyup(function(){ if(!binded1079){ $(window).bind('beforeunload',function(){ binded1079 = true; return "xxxx"; }); } var newCode = $(this).val() code1079 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code1079!=newCode){ // window.frames["iframe1079"].document.write("
"); // window.frames["iframe1079"].document.write(decodeHtml($("textarea#stepcodeTextarea1079").val())); // window.frames["iframe1079"].document.close(); // $(window.frames["iframe1079"]).load(function(){ // $("#iframe1079").height($("#iframe1079").contents().find("body").height()+showittryitheight); // }); // code1079 = newCode; // } }); $(".tryButton1079").click(function(){ $("#tryDiv1079").show(); $("#stepcodeTextarea1079").focus(); $("#stepcodeTextarea1079").height(200); $("#iframe1079").height(0); window.frames["iframe1079"].document.write("
"); window.frames["iframe1079"].document.write(decodeHtml($("textarea#stepcodeTextarea1079").val())); window.frames["iframe1079"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1079"]).load(function(){ $("#iframe1079").height($("#iframe1079").contents().find("body").height()+showittryitheight); }); $("#iframe1079").height($("#iframe1079").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor1079.focus(); editor1079.setSize(null, "250"); $("#rendering1079").hide(); $("#rendered1079").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor1079 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1079"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor1079.on("change",function(doc){ if(!binded1079){ $(window).bind('beforeunload',function(){ binded1079 = true; return "xxxx"; }); } var newCode = doc.getValue(); code1079 = newCode; $("textarea#stepcodeTextarea1079").val(newCode); if(alreadyWriteCode1079!=code1079){ lastModifedTime1079 = new Date().getTime(); $("#rendering1079").show(); $("#rendered1079").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor1079 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor1079.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv1079").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 6 :

变量类型判断

使用typeof来进行判断数据类型

正是因为变量是动态类型的,所以无法确定当前到底是哪种类型,这个时候,就可以使用typeof来进行判断
"); window.frames["iframe_show1080"].document.write(decodeHtml($("textarea#stepcodeTextarea1080").val())); window.frames["iframe_show1080"].document.close(); $(window.frames["iframe_show1080"]).load(function(){ $("#iframe_show1080").height($("#iframe_show1080").contents().find("body").height()+showittryitheight); }); $("#iframe_show1080").height($("#iframe_show1080").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<script> var x; document.write('声明了但是未赋值的时候,类型是: '+typeof x); document.write("<br>"); x=5; document.write('赋值为5之后,类型是: '+typeof x); document.write("<br>"); x=5.1; document.write('赋值为5.1之后,类型是: '+typeof x); document.write("<br>"); x=true; document.write('赋值为true之后,类型是: '+typeof x); document.write("<br>"); x="hello"; document.write('赋值为hello之后,类型是: '+typeof x); </script>
<script>
  var x; 
  document.write('声明了但是未赋值的时候,类型是: '+typeof x);
  document.write("<br>");
  x=5; 
  document.write('赋值为5之后,类型是: '+typeof x);
  document.write("<br>");
  x=5.1; 
  document.write('赋值为5.1之后,类型是: '+typeof x);
  document.write("<br>");
  x=true; 
  document.write('赋值为true之后,类型是: '+typeof x);
  document.write("<br>");
  x="hello"; 
  document.write('赋值为hello之后,类型是: '+typeof x);

</script>
"); window.frames["iframe1080"].document.write(decodeHtml(code1080)); window.frames["iframe1080"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1080"]).load(function(){ $("#iframe1080").height($("#iframe1080").contents().find("body").height()+showittryitheight); }); $("#iframe1080").height($("#iframe1080").contents().find("body").height()+showittryitheight); alreadyWriteCode1080 = code1080; $("#rendering1080").hide(); $("#rendered1080").show(); } var tRereshRetry2DemoPanel1080 = setInterval(rereshRetry2DemoPanel1080,1000); var binded1080 = false; $("textarea#stepcodeTextarea1080").keyup(function(){ if(!binded1080){ $(window).bind('beforeunload',function(){ binded1080 = true; return "xxxx"; }); } var newCode = $(this).val() code1080 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code1080!=newCode){ // window.frames["iframe1080"].document.write("
"); // window.frames["iframe1080"].document.write(decodeHtml($("textarea#stepcodeTextarea1080").val())); // window.frames["iframe1080"].document.close(); // $(window.frames["iframe1080"]).load(function(){ // $("#iframe1080").height($("#iframe1080").contents().find("body").height()+showittryitheight); // }); // code1080 = newCode; // } }); $(".tryButton1080").click(function(){ $("#tryDiv1080").show(); $("#stepcodeTextarea1080").focus(); $("#stepcodeTextarea1080").height(200); $("#iframe1080").height(0); window.frames["iframe1080"].document.write("
"); window.frames["iframe1080"].document.write(decodeHtml($("textarea#stepcodeTextarea1080").val())); window.frames["iframe1080"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe1080"]).load(function(){ $("#iframe1080").height($("#iframe1080").contents().find("body").height()+showittryitheight); }); $("#iframe1080").height($("#iframe1080").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor1080.focus(); editor1080.setSize(null, "250"); $("#rendering1080").hide(); $("#rendered1080").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor1080 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1080"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor1080.on("change",function(doc){ if(!binded1080){ $(window).bind('beforeunload',function(){ binded1080 = true; return "xxxx"; }); } var newCode = doc.getValue(); code1080 = newCode; $("textarea#stepcodeTextarea1080").val(newCode); if(alreadyWriteCode1080!=code1080){ lastModifedTime1080 = new Date().getTime(); $("#rendering1080").show(); $("#rendered1080").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor1080 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor1080.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv1080").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 7 :

空对象/对象不存在

null表示一个对象不存在,因为本章节讲的都是基本类型,而null是和对象相关的,所以会放在javascript中的对象中进行讲解


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


关于 前端部分-JavaScript-基本数据类型 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 620943819
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图