Node.js/默认值:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第9行: 第9行:
     this.name = arguments[0] ? arguments[0] : 'kangjian';
     this.name = arguments[0] ? arguments[0] : 'kangjian';
}</syntaxhighlight>
}</syntaxhighlight>
== \= ==
<syntaxhighlight lang="javascript">
function multiply(a, b = 1) {
  return a * b;
}
console.log(multiply(5, 2));
// expected output: 10
console.log(multiply(5));
// expected output: 5</syntaxhighlight>

2020年6月11日 (四) 13:31的版本

||

function Person(name){
    this.name = name || 'kangjian';
}

三元运算符

function Person(name){
    this.name = arguments[0] ? arguments[0] : 'kangjian';
}

\=

function multiply(a, b = 1) {
  return a * b;
}

console.log(multiply(5, 2));
// expected output: 10

console.log(multiply(5));
// expected output: 5