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>