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 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下