Professional Documents
Culture Documents
typically to keep
variables and functions with the same name separate.
code:
var greet = 'Hello!';
var greet = 'Hola!';
console.log(greet);
out:
Hola!
ie. these variables are created by different js files. this is a problem since one
will overwrite the other. namespaces can help.
in the case of namespaces, we will have a container for the english part and a
conatianer for the spanish part. we wil make namespaces by means of objects.
code:
var english = {};
var spanish = {};
english.greet = 'Hello!';
spanish.greet = 'Hola!';
console.log(english.greet);
//these 2 variables, even though they are both called greet, do not collide.