Advertisement
728x90
JavaScript doesn’t support namespaces by default. So if you create any element (function, method, object, variable) then it becomes global and pollutes the global namespace. Let's take an example of defining two functions without any namespace,
javascript
1function func1() {
2 console.log("This is a first definition");
3 }
4
5function func1() {
6 console.log("This is a second definition");
7}
8
9func1(); // This is a second definitionIt always calls the second function definition. In this case, namespaces will solve the name collision problem.
Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 35
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
291of476