JavaScript-学习一_var

时间:2024-10-06 14:33:32

  

JavaScript 数据类型

字符串(String)、数字(Number)、布尔(Boolean)、数组(Array)、对象(Object)、空(Null)、未定义(Undefined)。

<!DOCTYPE html>
<html>
<body>

<script>
var person={
firstname : "John",
lastname : "Doe",
id : 5566
};
document.write(person.lastname + "<br>");
document.write(person["lastname"] + "<br>");
</script>

</body>
</html>

<script>
var i;
var cars = new Array();
cars[0] = "Saab";
cars[1] = "Volvo";
cars[2] = "BMW";

for (i=0;i<cars.length;i++)
{
document.write(cars[i] + "<br>");
}
</script>

var carname=new String;
var x= new Number;
var y= new
Boolean;
var cars= new Array;
var person= new Object;