var i = 0;
while (i < 10) {
i++;
if (i % 2 == 0) {
continue;
}console.log(i);
}
for循环
for (var i = 0; i < 10; i++) {
console.log(i);
}
//输出数组
var week = ['SUN', 'MON', 'TUE', 'WEDN', 'THUR', 'FRI', 'SAT']
for (var i = 0; i < week.length; i++) {
console.log(week[i]);
}
函数
functionfunctionName(a,b){}
functionalertMessage() {
alert('hello');
}
alertMessage();
functionalertMessage(message) {
alert(message);
}
alertMessage('hello world');
var alertMessage = function(message) {
alert(message);
}
alertMessage('hello world');
var message='hello world';
var alertMessage = function(message) {
alert(message);
var message_1='hello';
}
var message_1='hello';
alertMessage();
对象 object
property(属性) method(方法)
var apple = {};
apple.color = 'red';
apple['weight'] = '10';
console.log(apple);
var apple = {
color: 'red',
weight: '10'
};
console.log(apple);
var apple = {
color: 'red',
weight: '10',
variety: [' red apple', 'green apple', ' Golden Apple']
};
console.log(apple);
apple.variety[0]
" red apple"
apple.variety[1]
"green apple"
apple.color='green'"green"
apple
Object {color: "green", weight: "10", variety: Array(3)}
delete apple.color
true
apple
Object {weight: "10", variety: Array(3)}
apple.color
undefined
var apple = {
color: 'red',
weight: '10',
variety: [' red apple', 'green apple', ' Golden Apple']
};
apple.showVariety = function() {for (var i = 0; i < this.variety.length; i++) {
document.writeln(this.variety[i]);
}
}
apple.showVariety();
var property;
for (property in apple) {
if (typeof apple[property] !== 'function')
console.log(apple[property]);
}
console.log(apple);