What happens if I don't pass a parameter in a Javascript function?

后端 未结 8 2158
余生分开走
余生分开走 2020-11-29 18:19

I am new to the world of Javascript and am tinkering with writing very basic functions and stumbled upon the example below by accident and am unsure why it works when I am n

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 18:43

    If you omit the argument, its value will be undefined. This enables you to create optional parameters quite easily.

    Another feature is the ability to define a function with no parameters, and call it with arguments successfully, making use of the arguments object. This lets you easily create variable-length argument arrays.

提交回复
热议问题