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

后端 未结 8 2190
余生分开走
余生分开走 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:59

    Because there's no error until the function expects to be able to work with the parameter that you're supposed to pass.

    For example:

    function myfunction(x) {
        return x*2;
    }
    

    Would throw an error; albeit probably only a NaN (in this case) or a variable is undefined.

提交回复
热议问题