仮引数のデフォルト値

仮引数にデフォルト値を=で指定できる。実引数が未指定又はundefinedが渡されると、デフォルト値になる。

function 関数(仮引数1, 仮引数2 = 'デフォルト', 仮引数3) {
  console.log(仮引数1, 仮引数2, 仮引数3)
}

関数(1) // 1 デフォルト undefined
関数(1, undefined, 3) // 1 デフォルト 3