or, What the heck is global abatement?
tldr: Global variables are code smells. Declaring variables inside an application-level function serves to namespace the variables and minimizes the use of global variables.
Javascript has function-level scoping, which means that variables declared anywhere within a function are scoped to that function. Writing a javascript without an enclosing function leaves your declared variables vulnerable to name collisions, or reassignment by other javascripts.
A global abatement is a strategy used to reduce the vulnerability of your javascript variables by removing them from the global scope. Application namespacing is one such strategy:
person = {
first_name: 'Hello',
last_name: 'Kitty'
};
var MYAPP = {};
MYAPP.person = {
first_name: 'Hello',
last_name: 'Kitty'
};
Declaring an application-level function ensures that the correct person
is called when needed. It improves readability by essentially flagging the scope of the variable and reducing ambiguity.