I’ve learned from experience that when programming javascript namespacing is a very important technique for keeping a clean code.

By definition the main goal of namespacing is avoiding collisions, but namespacing also helps in keeping a nice and clean code.By separating your code using namespacing easy to use packages of code can be created.
This is how to declare a variable and a function in a “my” namespace:

  1. var my = {};
  2. var my.url = 'www.google.ro';
  3. var my.sayHello = function (){
  4. alert('Hello');
  5. };

To call sayHello just:

  1. my.sayHello();

I recommend using namespacing in your implementation of javascript code.