Namespace can dramatically reduce the number of globals required and at the same time prevents the collisions or excessive name prefixing .
Consider this example
in this example all the functions,variables and objects are declared and polluting the global scope of your application . You can refactor this type of code by creating a single global object for your application , called for example Student and change all functions and variables to become properties of your global object
This pattern is good way to namespace your code and avoid naming collisions not only in your own code but collisions between your code and third-party code on the same page .
- More to type , prefixing every variable and function adds up in the total amount of code that needs to be downloaded
- Only one global instance as a result any part of the code can modify the global instance and the rest of the functionality gets the updated state
- Long nested names = slower property resolution lookups