4 ms·
In javascript, functions are closures. This means that the function "closes" over the environment in which it was defined. In the above example, the function ha
by drewolson 16y ago
In javascript, functions are closures. This means that the function "closes" over the environment in which it was defined. In the above example, the function has access to the sum variable because it was available at the time the function was defined. It is then free to add to that variable when the function is called at a later time.