Having Fun with Scopes Via Javascript
Javascript, Scope

Jonas' Conversation to you. Scopes like candy bars. Calling function a() with function (b) inside. function(a) is in the global scope. function(b) only exists within the "room" of function a().

This is a key difference between Ruby's access variables. The difference has to do with memory. The Ruby variables, perhaps they are restricted to a class or an object. But they all EXIST in memory. Your program is simply restricting access to them based on the rules that you've set.

Javascript functions out of scope do not exist. They are Schroedinger's cat: either dead or alive.

 

Most modern programming languages have a scope level between global(everyone can see it) and local (only this function can see it). JavaScript does not. (In ECMAScript 6 it does have a block-level scope called "let"). Thus, by default, everything that needs to be visible outside of the scope of a top-level function is visible everywhere.

 

| Back

Footerfull