In JavaScript, does it make a difference if I call a function with parentheses?

前端 未结 5 588
不知归路
不知归路 2020-11-22 02:13

I noticed a difference when calling a function with empty parentheses, or without any parentheses at all. However, I am not passing any arguments to the function so I wonder

5条回答
  •  野的像风
    2020-11-22 03:02

    initAll is a reference to a function value and the brackets operator appended to the function name RUNS this function object.

    So if you do something like

    a = initAll
    

    then a will become the same as initAll - for example you can do a() - but with

    a = initAll()
    

    the variable a will get the return value of the executed initAll function

提交回复
热议问题