<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script> //声明变量 let [x,y,z]=[10,20,30]; console.log(x,y,z); //从对象中获取指定值 let box={'name':'小庄','age':18}; let {name,age}=box; console.log(name,age); //``符号的使用,感觉最强大的地方转意'换行符',如果你用''换行需要加+。 let [myname,myage]=['小庄',23]; console.log(`hi,${myname}'s age is ${myage-1}`); //声明对象 let [up,sex]=['小庄','男']; let myObject={up,name}; console.log(myObject); //在对象中写函数 let myFun={ properties(){ console.log('方法执行了...'); } } myFun.properties(); //复制或合并对象 let object1={'name':'小庄','age':22}; let object2={'age':23}; let newObject={...object1,...object2}; console.log(newObject); //箭头函数 let ageFun=(m,n)=>(m>n?m-n:n-m); //一个参数+有返回值的示例:let ageFun=m=>100-m; console.log(ageFun(100,80)); </script> </head> <body> </body> </html>