Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:35:59+00:00 2026-06-15T03:35:59+00:00

What does it mean global namespace would be polluted? I don’t really understand what

  • 0

What does it mean global namespace would be polluted?

I don’t really understand what global namespace getting polluted means.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:36:00+00:00Added an answer on June 15, 2026 at 3:36 am

    Quick Note On Garbage Collection

    As variables lose scope, they will be eligible for garbage collection. If they are scoped globally, then they will not be eligible for collection until the global namespace loses scope.

    Here is an example:

    var arra = [];
    for (var i = 0; i < 2003000; i++) {
     arra.push(i * i + i);
    }
    

    Adding this to your global namespace (at least for me) should ad 10,000 kb of memory usage (win7 firefox) which will not be collected. Other browsers may handle this differently.

    Whereas having that same code in a scope which goes out of scope like this:

    (function(){
     var arra = [];
     for (var i = 0; i < 2003000; i++) {
      arra.push(i * i + i);
     }
    })();
    

    Will allow arra to lose scope after the closure executes and be eligible for garbage collection.

    Global Namespace Is Your Friend

    Despite the many claims against using the global namespace, it is your friend. And like a good friend, you should not abuse your relationship.

    Be Gentle

    Don’t abuse (usually referred to as “polluting”) the global namespace. And what I mean by do not abuse the global namespace is – do not create multiple global variables. Here is a bad example of using the global namespace.

    var x1 = 5;
    var x2 = 20;
    var y1 = 3
    var y2 = 16;
    
    var rise = y2 - y1;
    var run = x2 - x1;
    
    var slope = rise / run;
    
    var risesquared = rise * rise;
    var runsquared = run * run;
    
    var distancesquared = risesquared + runsquared;
    
    var distance = Math.sqrt(dinstancesquared);
    

    This is going to create 11 global variables which could possibly be overwritten or misconstrued somewhere.

    Be Resourceful

    A more resourceful approach, which does not pollute the global namespace, would be to wrap this all in the module pattern and only use one global variable while exposing multiple variables.

    Here is an example: (Please note this is simple and there is no error handling)

    //Calculate is the only exposed global variable
    var Calculate = function () {
     //all defintions in this closure are local, and will not be exposed to the global namespace
     var Coordinates = [];//array for coordinates
     var Coordinate = function (xcoord, ycoord) {//definition for type Coordinate
       this.x = xcoord;//assign values similar to a constructor
       this.y = ycoord;
      };
    
      return {//these methods will be exposed through the Calculate object
       AddCoordinate: function (x, y) {
       Coordinates.push(new Coordinate(x, y));//Add a new coordinate
      },
    
      Slope: function () {//Calculates slope and returns the value
       var c1 = Coordinates[0];
       var c2 = Coordinates[1];
       return c2.y - c1.y / c2.x - c1.x;//calculates rise over run and returns result
      },
    
      Distance: function () {
       //even with an excessive amount of variables declared, these are all still local
       var c1 = Coordinates[0];
       var c2 = Coordinates[1];
    
       var rise = c2.y - c1.y;
       var run = c2.x - c1.x;
    
       var risesquared = rise * rise;
       var runsquared = run * run;
    
       var distancesquared = risesquared + runsquared;
    
       var distance = Math.sqrt(distancesquared);
    
       return distance;
      }
     };
    };
    
    //this is a "self executing closure" and is used because these variables will be
    //scoped to the function, and will not be available globally nor will they collide
    //with any variable names in the global namespace
    (function () {
     var calc = Calculate();
     calc.AddCoordinate(5, 20);
     calc.AddCoordinate(3, 16);
     console.log(calc.Slope());
     console.log(calc.Distance());
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does [_\s^] mean underscore and whitespace but not (quote) in Reg I understand that
What does multiplexing mean (in it's abstract form)? I understand you have 'multiplexers' in
What does that mean? Getting this in the console during usage of my app
Example is a variable declaration within a function: global $$link; What does $$ mean?
What does this mean in C++: #define TheVLM(x) VLM::Global()->x TheVLM(Run());
This is regarding the PHP global variables. Does it mean the global variables are
When C says start-up values of global[/static] variables are zero, does it mean also
Possible Duplicates: What does “static” mean in a C program? Static vs global What
I am new to Python, and don't understand what .dtype does. For example: >>>
Does this mean I can't update another table from a trigger if I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.