js简单语法,循环
Posted 同心青年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js简单语法,循环相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js grammar</title> </head> <body> <script> //1.js语法 /* //https://www.cnblogs.com/yuanchenqi/articles/5980312.html // <script src="hello.js"> 引入方式 var a = 1; //声明变量时不用声明变量类型. 全都使用var关键字 var b = 2 ,c = "cc"; //一行可以申明多个变量,且不用是同类型 alert(a / b); alert(b / a); alert(c) function fun() { var va = "this is va"; //alert(va) document.write(va) // console.log(va) } fun() */ // 2.js数据类型 /*var a = 2; var b = false; var c = 2.1; var d = NaN; var e = undefined; var f = null; var obj = new Object(); console.log(typeof(a)); console.log(typeof(b)); console.log(typeof(c)); console.log(typeof(d)); console.log(typeof(e)); console.log(typeof(f)); console.log(typeof(obj)); var aa = "abc"+12; alert(aa) ; // abc12 //在js中false,ture分别代表0,1 var bb = 1+false; alert(bb); var cc = 2 + true; alert(cc);*/ /* alert("hello"+true); alert(parseInt(3.14)) alert(parseFloat("33.21"))*/ // var a = 1; // alert(a++); //先赋值后加减 a = a+1 a= 1 所以a++获取的是a的值之后a=2 // alert(a); //2 // alert(++a); //3 // alert(--a); //2 // alert(a--); //2 // alert(a); //1 // alert(null==undefined); true //alert(false==0); true //alert(true ==1); true //alert(true == 2); false //alert(undefined == 0); false //alert(5=="5"); true //alert(5==="5"); false var a = 1; var num = 0; for(a;a<=100;a++){ num += a; } alert(num); a = {"aa":"bb","cc":"dd"} for (var i in a) { console.log(i); console.log(a[i]); } b = ["a","b","c","d"]; for (var i in b){ console.log(i); console.log(b[i]); } var a; switch (5){ case 1: a = "aa"; break; case 2: a = "bb"; break; case 3: a = "cc"; break; default: a = "dd"; break; } alert(a) var c = 1; var counts = 0; while (c <=100){ counts += c; c+=1; } alert(counts) </script> </body> </html>
以上是关于js简单语法,循环的主要内容,如果未能解决你的问题,请参考以下文章