JS Coding Questions Logo
JS Coding Questions
#291💼 Interview💻 Code

Does JavaScript support namespaces

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 definition

It 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 Coding

Advertisement

728x90
291of476