There is no such thing as duplicate names in Javascript. You will never get an error re-declaring a name that already exists.
To avoid overwriting existing names in Javascript, good developers do at least one of the following things:
1) Carefully save your variables from the global scope, usually adding all the names needed for the application from just one or two objects with global scope.
// No
var foo = 1;
var bar = 2;
var bas = 3;
// Yes
var MyApp = {
foo:1,
bar:2,
bas:3
}
2) Make sure that the variable name has not yet been created before it is created.
var MyObj = {};
var MyObj = MyObj || {}
source
share