Posted on Arjun

Namespace in JavaScript

In this post i would like to explain about JavaScript Namespaces. Namespaces is nothing but grouping different functionality under the single unique name.As we know in JavaScript everything is in global scope so there are high chances to overriding functions(defining functions with same name more then one time). To avoid ambiguity and minimize the risk of naming collisions we use namespaces in JavaScript.

EX: Functions in global Scope

The above two function are in global Scope ,if you call test() at the end of the file you will get alert showing “test two”. because first test function is overwritten by second test() method.

So in order to overcome this situations we put that two method in two different variables.

Now if you want to access test() function , we have to write

Using namespaces we can write code structured,readable and easy to understand JavaScript code with out polluting the global namespace.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status