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

  • Home
  • SEARCH
  • 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 7045063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:29:03+00:00 2026-05-28T02:29:03+00:00

The basic example: var b = 10; var c = b; b++; console.log(b,c); >>

  • 0

The basic example:

var b = 10;
var c = b;
b++;
console.log(b,c);

>> 11 10

c looks like a copy of b.

But in another case:

var x = {};
var y = x;
x.abc = 10;
console.log(x.abc, y.abc);

>> 10 10

Why is the y not a copy of x, but a reference which points to the same instance x points to?

Also, I guessed b++ creates another instance, so b points to the new instance but c points to the old one. However…

var u = 10;
setTimeout(function() {
  console.log(u);
}, 10000)
u++;

>> 11

If u++ creates a new instance, then the u inside the anonymous function should point to the old u, shouldn’t it?

  • 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-28T02:29:04+00:00Added an answer on May 28, 2026 at 2:29 am

    the c looks like a copy of b.

    Both are references to the same immutable value.

    Why the y is not copy of x but a reference which points to the instance x points to?

    x was a reference to an object in the first place, so y is a copy of it (a copy of the reference, not a copy of the object).

    If u++ creates a new instance,

    It doesn’t.

    the u in anonymous function should points to the old u, shouldn’t it?

    u++ assigns a reference to 11 to u. The anonymous function is looking at u and not “the value of u at the time the function was created”.

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

Sidebar

Related Questions

i thought i had solved this but my basic example seems to not be
I'm trying to understand why this does not work. (Basic example with no validation
Attempting the most basic example of Knockout.js possible on their documentation page: http://knockoutjs.com/documentation/observables.html Looks
I need a basic example of how to use the IComparable interface so that
This is a very basic example of what I am trying to implement in
Does anyone have a basic example to display a UIPickerView when a UITextField was
i am looking for a basic example that shows how i could call a
If somebody may knows a blog posting with a basic example, that would help
What is the syntax for placing constraints on multiple types? The basic example: class
We have a Union Query. Here's a basic (similar) example: SELECT a.Name, b.Info FROM

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.