题目一
const numbers = [1, 2, 3]
numbers[5] = 6
console.log(numbers)
题目二
const colorConfig = {
red: true,
blue: false,
green: true,
black: true,
yellow: false
}
const colors = ["pink", "red", "blue"]
console.log(colorConfig.colors[1])
因为使用点表示法,所以JavaScript会尝试在colorConfig对象上找名为colors的属性,没有找到, 会返回undefined,且尝试使用[1]访问索引值为1的元素,因为无法对未定义的值执行此操作,所以会抛出错误Cannot read properties of undefined (reading '1')
题目三
const colorConfig = {
red: true,
blue: false,
green: true,
black: true,
yellow: false
}
const colors = ["pink", "red", "blue"]
console.log(colorConfig[colors[1]]) // true