[2015-12-10简介]每天看一点[JavaScript.DOM编程艺术(第2版)]
13:23~14:30 第2章
-------------------------------------------------------------------------------------------
1.数据类型
变量名: 字母 数字 $ _ (第一个不允许是数字)
下划线分隔每个单词
函数名: 驼峰格式命名 myMode
-------------------------------------------------------------------------------------------
2.声明变量,不需要进行类型声明:弱类型
var a = 'don\'t ask'
var a = "don't ask"
var a = -3.22222(任意位小数)
-------------------------------------------------------------------------------------------
3.数组
var aa = Array(4);
var aa = Array();
aa[0] = "john";
var aa = Array( "rr", 33, true);
var aa = [ "rr", 33, true];
var aa =Array();
var bb = [];
-------------------------------------------------------------------------------------------
4.对象
var lennon = Object();
lennon.name = "john";
var lennon = { na me:"John", year:1940, living:false };
-------------------------------------------------------------------------------------------
5.比较
var a =false;
var b = "";
if(a === b){
alert("a is b");
}else{
alert("a isnot b");
}
== 比较值
=== 比较值和类型
!= 比较值
!== 比较值和类型
逻辑 && || !
-------------------------------------------------------------------------------------------
6.循环
var count = 1;
while(count <=11){
alert(count);
count++;
}
do{
alert(count);
count++;
}while(count<11);
for(var count =1;count<11;count++){
alert(count);
}
var aa = [ "ruj", 33, false];
for(var count =0;count<aa.length;count++){
alert(count);
}
-------------------------------------------------------------------------------------------
7.函数
函数里 有var ----局部变量
无var ----全局变量
-------------------------------------------------------------------------------------------
var jeremy = new Person; //jeremy具备了Person的属性和方法
内建对象:Array Date Math等等
var current_date = new Date();
var today = current_date.getDay();
宿主对象:由浏览器提供的预定义对象:document form element等