Skip to content

Latest commit

 

History

History
19 lines (12 loc) · 625 Bytes

how_do_you_declare_namespace.md

File metadata and controls

19 lines (12 loc) · 625 Bytes

How do you declare namespace?

In JavaScript, namespaces are not natively supported, but you can simulate them using objects or modules. By declaring an object, you can encapsulate your functions and variables to avoid polluting the global scope.

Example using objects as namespaces:

const MyNamespace = {
  myFunction: function() { console.log('Hello!'); },
  myVariable: 42
};
MyNamespace.myFunction(); // 'Hello!'

Tags: intermediate, JavaScript, namespaces