JavaScript中最新添加了哪些运算符?
添加到JavaScript中的最新运算符是散布运算符和rest。
休息员
使用rest参数,您可以将参数数量表示为数组。ES6带来了rest参数,以简化开发人员的工作。对于参数对象,其余参数由三个点…表示,并在参数之前。
示例
让我们看下面的代码片段来定义rest参数
<html>
<body>
<script>
function addition(…numbers) {
var res = 0;
numbers.forEach(function (number) {
res += number;
});
return res;
}
document.write(addition(3));
document.write(addition(9,10,11,12,13));
</script>
</body>
</html>点差算子
它允许将表达式扩展为多个参数,元素,变量等。
示例
您可以尝试运行以下代码以了解如何使用传播算子
<html>
<body>
<script>
var a, b, c, d, e, f, g;
a = [10,20];
b = "rank";
c = [30, "points"];
d = "run"
//concat方法。
e = a.concat(b, c, d);
//点差运算符
f = [...a, b, ...c, d];
document.write(e);
document.write("<br>"+f);
</script>
</body>
</html>热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿