- 块级作用域
以前定义变量用var:
var name = "张三";
现在使用let
let name = "张三"
块的概念:
if(true) {
let name = "张三";
}```
console.log(name);
会报错误:name未定义,也就是说let定义的变量只能在块级作用域中使用。
2. const 定义常量
const name = "张三";
name = "李四";
浏览器报错,不可以修改。
const list = [];
list.push("张三");
list.push
![image.png](https://img.haomeiwen.com/i5695517/cab5b45e05e822ca.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://img.haomeiwen.com/i5695517/87ea91033ffa8929.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
模板字符串:
![image.png](https://img.haomeiwen.com/i5695517/ab59fcbf81d95721.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://img.haomeiwen.com/i5695517/88356ff0cd9daf2c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://img.haomeiwen.com/i5695517/35134a86ccd6d589.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://img.haomeiwen.com/i5695517/d083bb73ed928629.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://img.haomeiwen.com/i5695517/dc610c49cc99f7fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://img.haomeiwen.com/i5695517/20c48e1586e66cf5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
网友评论