Predict 错误类型
预测输出 中等
题目
什么类型的 错误做 这个 code produce?
代码
let arr = [1, 2, 3];
console.log(arr[10].toString());
提示
arr[10] 是 undefined 因为数组仅 有 3 元素.
解释
arr[10] 是 undefined (数组仅 有索引 0-2). Calling .toString() on undefined throws TypeError. 这个是 运行时错误 — code 是 syntactically 有效 and 开始运行, 但失败期间 execution 当它 tries 到 access 属性的 undefined.
相关资源
相关课程
- 错误
学习关于常见 programming 错误.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。