浏览器脚本语言的规范,而我们熟知的的js语言,如JavaSript则是规范的具体实现
for(var i=0; i<5; i++) console.log(i);
console.log("我再循环外" + i)
打印出来的 我在循环外5
for(let i=0; i<5; i++) console.log(i);
console.log("我再循环外" + i)
打印出来的是错误 i is not defined
let声明一个局部变量,const声明一个常量
const s = "hello es6"
s.includes("ec");
s.includes("es"); // true
s.startwith("he"); // true
s.startwith("es"); // false
const ss = `
hello
es6
hehe
`
let arr = [1,2,3];
//console.log(arr[1]); 传统的方式
let [x,y,z] = arr;
console.log(x,y,z);//1 2 3
let [x1] = arr;
console.log(x1); // 1
const person={
name:"jack",
age:21,
language:["java","js","html"]
};
let {name:n,age,language} = person;
console.log(n,age,language);
function fun1(a,b=1) // 如果传值,就正常,如果没传,就是默认值
{
//b = b || 1
console.log(a/b);
}
fun1(10);
前面是参数列表,后面是业务代码 ()=>{}
let fun2 = i => console.log(i);
let fun3 = (i,j) => {
const z = i + j;
console.log(z);
}
fun2(200);fun3(100,200);
const person = {
name : "zhangsan",
eat : function(x){
console.log(this.name + "吃" + x);
},
eat2 : (food) => console.log(person.name + "吃" + + x); // 箭头函数的this域是最外面
eat3(x) console.log(this.name + "吃" + + x);
}
person.eat1("dandan");
const p = {
name : "lisi",
age : 30
}
const fun3 = (ppp) => {console.log(ppp.name)}
const fun3 = ({name}) => {console.log(name)}
fun3(p)
let arr = [10,20,40]
const brr = err.map(a => a*10)
// ..........
arr.reduce( (a,b) => { a + b } ); // 60 == (10 + 20) + 30
arr.reduce( (a,b) => a + b , 100);
let person = {
name : "jack",
age : 12,
sex : 1,
username : "zhangsan"
}
Object.keys(person);
Object.values(person);
Object.entries(person); // [Array(2),Array(2),Array(2),Array(2)]
let pp = { age: "yyy" };
let pp1 = { xxx: "xxx" };
Object.assign(pp,person,pp1) // {age: "yyy",name:"jack",age:12,sex:1,username:"zhangsan"}
let arr = [10,20,30,40,60];
arr.find(a=>{a==30});
arr.find(a=>{a==30});