Asked • 06/19/19

Can someone explain this JavaScript auto executing function?

var foo = (function(){ var x = 0; return function(){return x++;}; })() Why the var x = 0 expression only runs once is my biggest misunderstanding about this.

1 Expert Answer


Sparky E. answered • 07/08/19

Computer Science Major, CTO at CollabTrade

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.