//const指令相关的用法
const ab = () => {
const arr = [1, 2, 5, 6, 4]
return console.log(arr.sort())
}
const arr = [1, , 2, 3, 4]
console.log(arr)
arr[0] = 10
console.log(arr)
const onj = {
name: '开开开',
age: 10
}
onj.name = '王五'
console.log(onj)
//输出会报错,const的值不存在提升
const a = 10
// a = 20
// 测试全局this
console.log(this)
//测试for循环
for (let i = 0; i < 10; i++) {
setTimeout(() => {
console.log(i)
}, 0)
}
for (var i = 0; i < 10; i++) {
setTimeout(() => {
console.log(i)
}, 0)
}
//测试let
let b = 10
console.log(b, '111')
b = 20
console.log(b, '222')
let str = [1, 2, 3, 4, 5]
console.log(str)
str = 10
console.log(str)
let aj = 10
let yi = () => {
console.log(aj)
let aj = 20
}
//let的块级作用域
{
let arr1 = 10
console.log(arr1, 'let的块级作用域')
}
// console.log(arr1, 'let的块级作用域')
//顶层
global.a = 10
// window.kk = 10
kk = 5
console.log(global.a, 'gf')
//解构赋值
//对象解构赋值
let astr = {
name: '夏舒涵',
sex: '女',
age: 10
}
let { name, sex, age } = astr
console.log('name', name)
let aks = {
as: 111,
bs: '辅导费',
c: {
d: '奋斗奋斗'
}
}
let {
as,
bs,
c: { d }
} = aks
console.log('aks', d)
//数组解构赋值
let bn = [1, 2, 3, 4]
let [hjk, , kkk] = [1, 2, 3]
console.log(hjk, kkk)
Es6声明变量的方法及不同2
最新推荐文章于 2024-08-25 09:57:22 发布