JavaScript Namespacing Nested Namespaces

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

When multiple modules are involved, avoid proliferating global names by creating a single global namespace. From there, any sub-modules can be added to the global namespace. (Further nesting will slow down performance and add unnecessary complexity.) Longer names can be used if name clashes are an issue:

 var NavigationNs = NavigationNs || {};
     NavigationNs.active =  {};
     NavigationNs.pagination = {};
     NavigationNs.redirection = {};
    
     // The second level start here.
     Navigational.pagination.jquery = function();
     Navigational.pagination.angular = function();
     Navigational.pagination.ember = function();


Got any JavaScript Question?