Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zh-cn]: Update translation of String.concat() #14111

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,54 @@ slug: Web/JavaScript/Reference/Global_Objects/String/concat

{{JSRef}}

**`concat()`** 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。
**`concat()`** 方法将字符串参数连接到调用的字符串,并返回一个新的字符串。

{{EmbedInteractiveExample("pages/js/string-concat.html")}}

## 语法

```plain
str.concat(str2, [, ...strN])
```js-nolint
concat(str1)
concat(str1, str2)
concat(str1, str2, /* …, */ strN)
```

### 参数

- `str2 [, ...strN]`
- : 需要连接到 `str` 的字符串
- `strN`
- : 要连接到 `str` 的一个或多个字符串

### 返回值

一个新的字符串,包含参数所提供的连接字符串
一个包含所提供的多个字符串文本组合的新字符串

## 描述

`concat` 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。 `concat` 方法并不影响原字符串
`concat()` 函数将字符串参数连接到调用的字符串并返回一个新字符串。对原字符串或返回的字符串所做的更改不会影响另一个字符串

如果参数不是字符串类型,它们在连接之前将会被转换成字符串。

## 性能

强烈建议使用[赋值操作符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Assignment_Operators)(`+`, `+=`)代替 `concat` 方法。
`concat()` 方法与 [加号/字符串连接运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)(`+`,`+=`)非常相似,不同之处在于 `concat()` 直接将其参数强制转换为字符串进行连接,而加号运算符首先将其操作数强制转换为原始值,然后再进行连接。有关更多信息,请参阅[`+`运算符的参考页面](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)。
JasonLamv-t marked this conversation as resolved.
Show resolved Hide resolved

## 示例

### 使用 `concat`
### 使用 concat()

下面的例子演示如何将多个字符串与原字符串合并为一个新字符串
JasonLamv-t marked this conversation as resolved.
Show resolved Hide resolved

```js
let hello = 'Hello, '
console.log(hello.concat('Kevin', '. Have a nice day.'))
const hello = "Hello, ";
console.log(hello.concat("Kevin", ". Have a nice day."));
// Hello, Kevin. Have a nice day.

let greetList = ['Hello', ' ', 'Venkat', '!']
"".concat(...greetList) // "Hello Venkat!"
const greetList = ["Hello", " ", "Venkat", "!"];
"".concat(...greetList); // "Hello Venkat!"

"".concat({}) // [object Object]
"".concat([]) // ""
"".concat(null) // "null"
"".concat(true) // "true"
"".concat(4, 5) // "45"
"".concat({}); // "[object Object]"
"".concat([]); // ""
"".concat(null); // "null"
"".concat(true); // "true"
"".concat(4, 5); // "45"
```

## 规范
Expand All @@ -61,7 +63,7 @@ let greetList = ['Hello', ' ', 'Venkat', '!']

{{Compat}}

## 相关链接
## 参见

- {{jsxref("Array.prototype.concat()")}}
- {{jsxref("Operators/Assignment_Operators", "Assignment operators", "", 1)}}
- [加法运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Addition)