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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:46:50+00:00 2026-06-17T18:46:50+00:00

I have lived under the assumption that there are primitive types and reference types

  • 0

I have lived under the assumption that there are primitive types and reference types in Javascript. On a day-to-day basis, I’ve never had this impact me but I was just starting to a lot more JS and wanted to update my ‘thinking’. In other words, I would have betted $20 that the following would return 68

var my_obj = {};
var tmp_obj = {};

tmp_obj.my_int = 38;
my_obj.tmp_val = tmp_obj.my_int;
tmp_obj.my_int = 68;

alert('68 means reference, 38 means primitve: ' + my_obj.tmp_val);

but it returns 38.

enter image description here

Are all instances of numbers primitive types even if they exist in the context of a reference type? If y, I’m really surprised and find that odd behavior(and would be out $20). Or is my example not demonstrating what I think it is?

thx in advance

UPDATE #1

Wow, thx for all the answers. Here’s a slight change which helps me a lot in understaning:

var my_obj={};
var tmp_obj={};
var my_obj_2=tmp_obj;
tmp_obj.my_int=38;
my_obj.tmp_val=tmp_obj.my_int;
tmp_obj.my_int=68
alert('68 means reference, 38 means primitve: ' + my_obj.tmp_val);   // 38
alert('68 means reference, 38 means primitve: ' + my_obj_2.my_int);  // 68
my_obj_2.my_int=78;
alert(tmp_obj.my_int); // tmp_obj is now 78 ie two way
  • 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-17T18:46:51+00:00Added an answer on June 17, 2026 at 6:46 pm

    You example would work as expected if you had

         my_obj = tmp_obj;
    

    Then, all the properties would point to the same reference since there would only be one object.

    But when you write

         my_obj.tmp_val = tmp_obj.my_int;
    

    then my_obj.tmp_val will take the value that’s stored in tmp_obj.my_int but that doesn’t create a new reference between the 2 objects.

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

Sidebar

Related Questions

I have a live database that had some data deleted from it and I
I have two different kinds of objects that I'd like to live under the
We have a Mono application under Linux that does image processing on a bunch
I have a Python script running under Linux that generates huge numbers of tiny
Let's say I have this blob of code that's made to be one long-running
I have a python app which is supposed to be very long-lived, but sometimes
I am loading content into a page with ajax that will have live click
I have some Oracle tables that represent a parent-child relationship. They look something like
I have a Tomcat Java webapp which is thrashing the Java GC when under
I have a great idea for a 3D network game, and I've concluded that

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.