How best to determine if an argument is not sent to the JavaScript function

后端 未结 13 651
猫巷女王i
猫巷女王i 2020-11-28 00:40

I have now seen 2 methods for determining if an argument has been passed to a JavaScript function. I\'m wondering if one method is better than the other or if one is just ba

13条回答
  •  渐次进展
    2020-11-28 01:36

    function example(arg) {
      var argumentID = '0'; //1,2,3,4...whatever
      if (argumentID in arguments === false) {
        console.log(`the argument with id ${argumentID} was not passed to the function`);
      }
    }
    

    Because arrays inherit from Object.prototype. Consider ⇑ to make the world better.

提交回复
热议问题