API Reference > @easyops-cn/brick-next-pipes > add
add() function
数学加法或字符串拼接。
Mathematics
Signature:
export declare function add(
value: number | string,
operand: number | string
): number | string;
Parameters
| Parameter | Type | Description |
|---|---|---|
| value | number | string | 值。 |
| operand | number | string | 操作数。 |
Returns:
number | string
如果其中一个参数为字符串,返回字符串,否则返回数字。
Remarks
详见 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition。
Example
数学加法:
// Number + Number -> addition
1 + 2; // 3
// Boolean + Number -> addition
true + 1; // 2
// Boolean + Boolean -> addition
false + false; // 0
字符串拼接:
// String + String -> concatenation
"foo" + "bar"; // "foobar"
// Number + String -> concatenation
5 + "foo"; // "5foo"
// String + Boolean -> concatenation
"foo" + false; // "foofalse"