参考资料:
1. http://www.w3school.com.cn/js/js_datatypes.asp
2. http://blog.sina.com.cn/s/blog_85c1dc1001013u7z.html
☂ 知识点:
☞ Javascript拥有动态类型。
☞ undefined表示变量不含值。
☞ null用于清空变量。
- 字符串
var answerOne="Nice to meet you!"; var answerTwo="He is called 'Bill'"; var answerThree='He is called "Bill"';
- 数字
var x1=34.00; //使用小数点来写 var x2=34; //不使用小数点来写 var y=123e5; // 12300000 var z=123e-5; // 0.00123
- 布尔
var x=true var y=false
- 数组
var carsOne=new Array(); cars[0]="Audi"; cars[1]="BMW"; cars[2]="Volvo"; var carsTwo=new Array("Audi","BMW","Volvo"); var carsThree=["Audi","BMW","Volvo"];
- 对象
var person={firstname:"Bill", lastname:"Gates", id:5566}; var person={ firstname : "Bill", lastname : "Gates", id : 5566 }; person=new Object(); person.firstname="Bill"; person.lastname="Gates"; person.age=56; person.eyecolor="blue"; person.autoplay=function(){ alert("play......."); } name=person.lastname; name=person["lastname"];
- 声明变量类型
可以用关键字new来声明变量的类型。
var carname=new String; var x= new Number; var y= new Boolean; var cars= new Array; var person= new Object