# Protecting Your Scripts with Namespaces
As the complexity of your web projects grows, you will eventually run into a situation where you are sharing the code writing duties with another person. You may or may not know the person. You may or may not be in contact with that person. You may just be using a JavaScript file provided to you by a previous employee at your company.
Now, without opening their 3000 line JavaScript file and looking at all the function names... how can you write your JavaScript file in a way that will never conflict with theirs? How can you be sure that your variable and functions won't collide with theirs?
The answer is by namespacing your file.
Come up with a single unique name for your JavaScript. Use that as the name of your first object which will contain ALL your code.
let STEVE = {
version: 1.0,
date: '19/10/2016',
num: 17,
str: 'Hello World',
message: function(msg) {
console.log('STEVE says', msg);
},
};
2
3
4
5
6
7
8
9
If this is my JavaScript file then I have a single object which contains four properties: version, num, str, and date; plus a single method called message.
To use my code from some other JS file:
let myMessage = 'As of ' + STEVE.date + ' we are at version ' + STEVE.version;
STEVE.message(myMessage);
2
Every time I want to use one of the properties or methods from my file I just prefix them with STEVE. .
I can now pass my file off to anyone else to use. They can call their variables whatever they like. As long as they avoid one name - STEVE, then we are good to go.
This process is known as namespacing.