DEV Community

Discussion on: 6 Advanced JavaScript Concepts You Should Know

Collapse
jessycormier profile image
Jessy Cormier

An alternative way to do namespacing

let MyNameSpace = MyNameSpace || {};
MyNameSpace.SubNameSpace = MyNameSpace.SubNameSpace || {};
Enter fullscreen mode Exit fullscreen mode

you're defaulting to an object literal when the namespace isn't defined. In normal non-framework JS code this lets you build out modules and assign them to namespaces as well as separate code into many files allowing to to define namespaces without the direct checking.