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 6890891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:20:23+00:00 2026-05-27T06:20:23+00:00

Let’s say I start up a var for an Object in my code var

  • 0

Let’s say I start up a var for an Object in my code

var base = {x:Infinity, y:Infinity};

and later in the same scope I do

var base = {x:0, y:0}

I get that I can re-use the existing variable, but I’m trying to iterate on a point.

  1. Does this cause any problems for the current scope as far as memory is concerned?
  2. Would there be any problems if these are in different scopes?
  3. Is the general rule to never use var on an already-existing variable?
  4. If I did this several (thousands) of times, would I run into any “funky” issues?
  • 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-05-27T06:20:24+00:00Added an answer on May 27, 2026 at 6:20 am
    1. It releases its hold on the old value, so it can be potentially garbage collected. I say potentially, because objects can be referenced by different variables.

    2. If they’re in different scopes, the inner base will shadow the outer one (assuming you’re talking about nested scopes), so the old value will not be overwritten. Shadowing is usually best avoided.

    3. Generally, within the same scope, yes but that’s more of a coding style aspect. It won’t make an effective difference in the execution since there’s only one declaration no matter how many times you declare the same var in the same scope.

    4. Depends. Are you talking about overwriting in a loop? If you no longer need the current value, it shouldn’t be an issue.


    To be clear, when you do this:

    var base = {x:Infinity, y:Infinity};
    
    var base = {x:0, y:0}
    

    What’s really happening is this:

    var base;  // declaration is hoisted
    
    base = {x:Infinity, y:Infinity};  // new object is referenced by base
    
    base = {x:0, y:0}  // previous object is released, and new object is referenced
    

    Note that when I talk about scope and var, I’m talking specifically about function scope. In standard JavaScript/ECMAScript implementations, there is no block scope, so there’s no special meaning when using var in a for statement for example.

    As mentioned by @Charles Bailey, Mozilla has let, which does allow scoping in blocks, but it would require that specific keyword. The var statement doesn’t recognize the block with respect to variable scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I can call a method like this: core::get() . What is the
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say I have some text as follows: do this, do that, then this,
Let's say, I have a .NET 2 installed. Can I programmatically install version 4
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString
Let's suppose I have a Discussion model, and that a discussion can be tagged.
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say that I have a set of relations that looks like this: relations

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.