1.为什么需要const
// let
let sex = 'male'
sex = 'female'
console.log(sex)
// const
const sex = 'male'
sex = 'female'
console.log(sex)
// const 就是为了那些一旦初始化就不希望重新赋值的情况设计的
2.const 的注意事项
// 2.1.使用const声明常量,一旦声明,就必须立即初始化,不能留到以后赋值
// 错误用法
const sex
sex = 'male'
// 正确用法
const sex = 'male'
// 2.2.const 声明的常量,允许在不重新赋值的情况下修改它的值
// 基本数据类型
// const 声明的常量没有办法修改基本数据类型的值
// const sex = 'male'
// sex = 'female'
// 引用数据类型
// const person = { username: 'Alex' }
// person.username = 'ZhangSan'
// console.log(person)
3.什么时候用const,什么时候用let
// for (let i = 0; i < 3; i++){}
// 不知道用什么的时候先用const方便以后有报错提醒