Javascript 基礎
宣告
var message;
字串
var message = '哈囉';
var name = "alincode";
數字
var num1 = 1;
var num2 = 1.5;
等於
- ===:Strict equality
- ==:Loose equality
var x = 5;
console.log(x == 5);
console.log(x == "5");
console.log(x === "5");
陣列
var people = [{
firstname: 'ailin',
lastname: 'liou'
},{
firstname: 'Jane',
lastname: 'Doe'
}
];
var lang = ['中文', '英文'];
// 陣列長度
lang.length;
lang.forEach(function(item) {
console.log(item);
});
函式
function greet() {
console.log('哈囉');
}
greet();
callback 函式
var lang = ['中文', '英文'];
function callback(item) {
console.log(item);
}
lang.forEach(callback);