1. let 与 const
let 声明的变量只在 let 命令所在的代码块内有效。
const 声明一个只读的常量,一旦声明,常量的值就不能改变。
2.标签模板字符串
const name ="why"
const age =18
//1.基本用法
//1.1.ES6之前
//const info = "my name is" + name + ",",age is "+ age
//1.2.ES6之后
const info =`my name is ${name}, age is ${age}`
console.log(info)//my name is why, age is 18
//2.标签模板字符串的用法
function foo(...args){
console.log("参数:",args)
}
foo("why",18,1.88)//参数: ['why', 18, 1.88]
foo`my name is ${name},age is ${age},height is ${1.88}`//参数: [Array(4), 'why', 18, 1.88]
3.ES8 字符串填充方法 padStart padEnd
const minute ="5".padStart(2,0)
const second="6".padStart(2,0)
console.log(`${minute}:${second}`)
//结果 05:06
4.ES11,Nullish Coalescing Operator增加了空值合并操作符
const foo = ""
const result1 =foo||"默认值"
const result2 = foo ??"默认值"
console.log(result1)//默认值
console.log(result2)//""