資料型別

JavaScript 變數可以包含許多資料型別:數字,字串,陣列,物件等:

// Number
var length = 16;

// String
var message = "Hello, World!"; 

// Array
var carNames = ['Chevrolet', 'Nissan', 'BMW']; 

// Object
var person = {
    firstName: "John",
    lastName: "Doe"
}; 

JavaScript 具有動態型別。這意味著同一個變數可以用作不同的型別:

var a;              // a is undefined
var a = 5;          // a is a Number
var a = "John";     // a is a String