var callbacks = []
for (var i = 0; i < 4; i++) {
callbacks.push(function() {
console.log(i);
});
}
callbacks.forEach(cb => cb());
输出为4,4,4,4
for循环里的函数没有直接调用,只是把4个一模一样的函数添加到数组里,再通过遍历调用每一个数组元素(函数),因为i=4跳出循环,所以console.log(i)全部打印4
const number = [1, 2, 3, 4, 5, 4, 3, 2, 1];
console.log(number.lastIndexOf(4)); ( )
输出为5
lastIndexOf() 方法可返回一个指定的字符串值最后出现的位置