unrealFunctionToUnderstand
is a function. When called it logs "I'm calling once time! :D".
It also returns another function (tryToUnderstandThis
) when called.
After defining this function you are (1) calling it unrealFunctionToUnderstand()
, then (2) assigning it's returned value (tryToUnderstandThis
) to hardcoreLesson
. Then you are calling hardcoreLesson
(reference to tryToUnderstandThis
) twice and logging the result.
So you are calling unrealFunctionToUnderstand
once, and it logs "I'm calling once time! :D", then calling tryToUnderstandThis
twice, and it logs "666" twice.
Can you notice how I "ran" this code on paper? This is how you answer questions like this yourself. You interpret the code the same way the browser would, on paper. It becomes easier to pinpoint language constructs you don't understand or know yet, so you can first learn / ask about those. Then, if you understand each part, it becomes clear what is executed and why.