Skip to content

字符串

一句话解释

字符串 是 序列 的 characters used 到 represent 文本, enclosed in 单个, 双, or backtick quotes.

用大白话说

A string is text — a sequence of zero or more characters. JavaScript strings are immutable: once created, their contents cannot be changed (though you can create new strings from them).

Strings can be written with single quotes ('hello'), double quotes ("hello"), or backticks (`hello). Backticks create template literals, which support multi-line text and ${表达式}` interpolation.

Common string methods include slice, 拆分, replace, toUpperCase, trim, 包含, and indexOf. Strings are iterable — you can loop over their characters with for...的.

示例

javascript
const name = "Ada";
const greeting = `Hello, ${name}!`;
console.log(greeting);          // "Hello, Ada!"
console.log(name.toUpperCase()); // "ADA"
console.log(name.length);        // 3

Template literals interpolate 表达式; 字符串 有 方法 and 长度 属性.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表