javascript - While assigning a function to a variable in JS, why does it gets executed automatically? -
i come python background, , partially understand concept of functions being first class objects in python , javascript.
but behaviour looks unusual me:
$ node > function calc(){console.log('hey');}; > var = calc() hey
the ()
in sample [var = calc();] means want invoke function.
if want assign function variable should -
var = calc;
then, if want invoke can use
a();
Comments
Post a Comment