Spot 字符串索引 Bug
找错误 简单
题目
This code should get the first character but gets undefined. What is wrong?
代码
const name = "Ada";
console.log(name[3]);
提示
字符串是 零-indexed, 只是如 数组.
解释
Strings are indexed starting at 0. "Ada" has characters at indices 0 (A), 1 (d), 2 (a). Index 3 is out of bounds and returns undefined. To get the first character, use name[0] which gives "".
相关资源
相关课程
- 字符串 and 文本
学习如何字符串 and 文本工作 in programming.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。