JS基础知识入门教程
JavaScript是一种轻量级的编程语言,简称JS。JS是可插入 HTML 页面的编程代码,JS插入 HTML 页面后,可由所有的现代浏览器执行。JS主要包括BOM操作和DOM操作。var声明变量,分号结束,+为字符串的连接符,JS变量是动态的,可以用不同的类型。变量类型有字符串(String)、数字(Number)、布尔(Boolean)、数组(Array)、对象(Object)、空(Null)、未定义(Undefined),JS基本的语句有if语句,if else语句,while语句 ,for语句。下面雷雪松给大家分享JS基础知识入门教程。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | //字符串 var name = "leixuesong"; //字符串长度 name.length; //数字 var age = 20; //数组循环 var arr = [1,2,3]; for(var i=0;i<arr.length;i++){ console.log("index:" +i+"--value:"+arr[i]); } //数组长度 arr.length; //对象 var obj = {name:"leixuesong",age:"21"}; //对象遍历 for(i in obj){ console.log("key:" +i+"--value:"+obj[i]); } //null var cars=null; var a = 10; var b = 20; //if语句 if(a < b){ console.log("a小于b!"); } if(b > a){ console.log("b大于a!"); } if(a != b){ console.log("两个数值不相等!"); } //if else语句 if( a == b){ console.log("两个数值相等!"); }else{ console.log("两个数值不相等!"); } if( a < b){ console.log("a小于b!"); }else if(a == b){ console.log("a相等b!"); }else{ console.log("a大于b!"); } //switch语句 var day=new Date().getDay(); switch (day) { case 0: x="Today it's Sunday"; break; case 1: x="Today it's Monday"; break; case 2: x="Today it's Tuesday"; break; case 3: x="Today it's Wednesday"; break; case 4: x="Today it's Thursday"; break; case 5: x="Today it's Friday"; break; case 6: x="Today it's Saturday"; break; } //for语句 for (var i=0; i<5; i++){ console.log(i); } //while语句 while (i<5){ console.log(i); i++; } //do/while 循环 do{ console.log(i); i++; }while(i<5) 九九乘法表 var str = ""; for(var i =1 ; i <=9; i++){ for(var j = 1; j <=i ; j++){ str+=i + " * " + j + " = " + i*j + " "; } str+= "<br />"; } document.write(str); |
来源:JS基础知识入门教程
2016年8月12日 下午2:34
我感觉这个挺好用的呢
2016年9月12日 下午3:17
js用到的地方很多
2019年5月5日 下午8:44
哇塞,居然是沙发?留个名
2019年5月5日 下午9:04
哇塞,居然是沙发?留个名
2019年5月9日 下午8:45
哇塞,居然是沙发?留个名
2019年5月10日 下午11:46
看过了。很好很强大。