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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -