Skip to main content
Version: 2.x

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

ParameterTypeDescription
valuenumber | string值。
operandnumber | 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"