//let不存在變量提升
console.log(name);
let name = "xiaoming";
//Uncaught ReferenceError: name isnot defined
箭頭函數和this
var bob = {
_name: "bob",
_friends: ["a", "b"],
printFriends(){
this._friends.forEach(f =>{
console.log(`${this._name} knows ${f}`)
})
}
}
function s(){
letf = () => {
let numbers = [];
for(let n of arguments){
numbers.push(n*n);
}
return numbers;
}
return f();
}
模板字符串
console.log(`this will be printed in a line`)
console.log(`this will be printed
in multiline`)
var name = "xiaoming", age = 10;
console.log(`${name} is ${age} years old`);
//不轉義轉義符輸出
console.log(String.raw`In ES5 "\n" is a line-feed.`)