My understanding is that this is actually very simple:

  • Javascript is always pass by value, but when a variable refers to an object (including arrays), the "value" is a reference to the object.
  • Changing the value of a variable never changes the underlying primitive or object, it just points the variable to a new primitive or object.
  • However, changing a property of an object referenced by a variable does change the underlying object.

So, to work through some of your examples:

function f(a,b,c) {
    // Argument a is re-assigned to a new value.
    // The object or primitive referenced by the original a is unchanged.
    a = 3;
    // Calling b.push changes its properties - it adds
    // a new property b[b.length] with the value "foo".
    // So the object referenced by b has been changed.
    b.push("foo");
    // The "first" property of argument c has been changed.
    // So the object referenced by c has been changed (unless c is a primitive)
    c.first = false;
}

var x = 4;
var y = ["eeny", "miny", "mo"];
var z = {first: true};
f(x,y,z);
console.log(x, y, z.first); // 4, ["eeny", "miny", "mo", "foo"], false

Example 2:

var a = ["1", "2", {foo:"bar"}];
var b = a[1]; // b is now "2";
var c = a[2]; // c now references {foo:"bar"}
a[1] = "4";   // a is now ["1", "4", {foo:"bar"}]; b still has the value
              // it had at the time of assignment
a[2] = "5";   // a is now ["1", "4", "5"]; c still has the value
              // it had at the time of assignment, i.e. a reference to
              // the object {foo:"bar"}
console.log(b, c.foo); // "2" "bar"
Answer from nrabinowitz on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference
JavaScript reference - JavaScript | MDN
The JavaScript reference serves as a repository of facts about the JavaScript language. The entire language is described here in detail. As you write JavaScript code, you'll refer to these pages often (thus the title "JavaScript reference").
🌐
W3Schools
w3schools.com › jsrEF › default.asp
JavaScript and HTML DOM Reference
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
DevDocs
devdocs.io › javascript
DevDocs — JavaScript documentation
JavaScript API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
🌐
SitePoint
sitepoint.com › blog › javascript › quick tip: how javascript references work
Quick Tip: How JavaScript References Work — SitePoint
November 6, 2024 - To modify the original compound value, modify the existing compound value that the reference is pointing to. TL;DR: There are NO pointers in JavaScript and references work differently from what we would normally see in most other popular programming languages.
🌐
W3Schools
w3schools.com › jsref › jsref_reference.asp
JavaScript Reference
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
Reddit
reddit.com › r/learnjavascript › javascript reference guide
r/learnjavascript on Reddit: JavaScript reference guide
May 1, 2019 -

can anyone one guide me on how to learn javaScript?

i am new in the world of programming so i dont realy know from where to start. i have already kind of finished HTML and CSS and now looking forward to learn javaScript so any references you provide can be a big help to me

Find elsewhere
Top answer
1 of 4
727

My understanding is that this is actually very simple:

  • Javascript is always pass by value, but when a variable refers to an object (including arrays), the "value" is a reference to the object.
  • Changing the value of a variable never changes the underlying primitive or object, it just points the variable to a new primitive or object.
  • However, changing a property of an object referenced by a variable does change the underlying object.

So, to work through some of your examples:

function f(a,b,c) {
    // Argument a is re-assigned to a new value.
    // The object or primitive referenced by the original a is unchanged.
    a = 3;
    // Calling b.push changes its properties - it adds
    // a new property b[b.length] with the value "foo".
    // So the object referenced by b has been changed.
    b.push("foo");
    // The "first" property of argument c has been changed.
    // So the object referenced by c has been changed (unless c is a primitive)
    c.first = false;
}

var x = 4;
var y = ["eeny", "miny", "mo"];
var z = {first: true};
f(x,y,z);
console.log(x, y, z.first); // 4, ["eeny", "miny", "mo", "foo"], false

Example 2:

var a = ["1", "2", {foo:"bar"}];
var b = a[1]; // b is now "2";
var c = a[2]; // c now references {foo:"bar"}
a[1] = "4";   // a is now ["1", "4", {foo:"bar"}]; b still has the value
              // it had at the time of assignment
a[2] = "5";   // a is now ["1", "4", "5"]; c still has the value
              // it had at the time of assignment, i.e. a reference to
              // the object {foo:"bar"}
console.log(b, c.foo); // "2" "bar"
2 of 4
62

Javascript always passes by value. However, if you pass an object to a function, the "value" is really a reference to that object, so the function can modify that object's properties but not cause the variable outside the function to point to some other object.

An example:

function changeParam(x, y, z) {
  x = 3;
  y = "new string";
  z["key2"] = "new";
  z["key3"] = "newer";

  z = {"new" : "object"};
}

var a = 1,
    b = "something",
    c = {"key1" : "whatever", "key2" : "original value"};

changeParam(a, b, c);

// at this point a is still 1
// b is still "something"
// c still points to the same object but its properties have been updated
// so it is now {"key1" : "whatever", "key2" : "new", "key3" : "newer"}
// c definitely doesn't point to the new object created as the last line
// of the function with z = ...
🌐
Javascript-reference
javascript-reference.info
JavaScript Reference
Contents: Number String Number <–> String Boolean Date Math Array Function logic Object type object-orientation Error (exceptions) LEGEND Operator Precedence · More content is in the product closeups, especially: DOM (Document Object Model) Regular Expressions
🌐
BrainStation®
brainstation.io › learn › javascript › reference
JavaScript Reference (2026 Tutorial & Examples) | BrainStation®
February 4, 2025 - This guide is intended to be used alongside BrainStation’s free interactive JavaScript tutorial to help you learn the fundamentals of programming with JavaScript before you get started working hands-on with real JavaScript code. This reference guide will provide an introduction to the JavaScript programming language for beginners, with an overview of JavaScript’s history and origins, definitions of key JavaScript syntax, concepts, and terminology, and examples of sample JavaScript code.
🌐
Pressbooks
ecampusontario.pressbooks.pub › webdev › chapter › javascript-reference
JavaScript Reference – Full Stack Web Development for Beginners
Here are some quick reference reminders about JavaScript. This textbook is just designed to give you a toehold in how to use JavaScript for client-side…
🌐
Unibo
lia.disi.unibo.it › materiale › JS › developer.mozilla.org › en-US › docs › Web › JavaScript › Reference.html
JavaScript reference - JavaScript | MDN
Provides a statement with an identifier that you can refer to using a break or continue statement. ... Extends the scope chain for a statement. This chapter documents all the JavaScript expressions and operators.
🌐
Web Reference
webreference.com › javascript
Intro to JavaScript | WebReference
As you continue to learn and work with JavaScript, there are a few key concepts and best practices that you should keep in mind. First, it is important to understand the difference between declaration and initialization of variables. When you declare a variable, you are simply creating a reference ...
🌐
Medium
medium.com › @naveenkarippai › learning-how-references-work-in-javascript-a066a4e15600
Learning how references work in JavaScript | by Naveen Karippai | Medium
January 14, 2023 - When the compound value in a variable is reassigned, a new reference is created. In JavaScript, unlike in most other popular programming languages, the references are pointers to values stored in variables and NOT pointers to other variables, ...
🌐
Dave Ceddia
daveceddia.com › javascript-references
A Visual Guide to References in JavaScript
May 8, 2020 - References are everywhere in JS, but they’re invisible. They just look like variables. Some languages, like C, call these things out explicitly as pointers, with their own syntax to boot. But JS doesn’t have pointers, at least not by that name. And JS doesn’t have any special syntax for them, either. Take this line of JavaScript for example: it creates a variable called word that stores the string “hello”.
🌐
QuickRef.ME
quickref.me › home › javascript cheat sheet & quick reference
JavaScript Cheat Sheet & Quick Reference
A JavaScript cheat sheet with the most important concepts, functions, methods, and more. A complete quick reference for beginners.
🌐
Amazon
amazon.com › JavaScript-Complete-Reference-Thomas-Powell › dp › 0072191279
JavaScript: The Complete Reference: Powell, Thomas A., Schneider, Fritz: 9780072191271: Amazon.com: Books
A comprehensive guide, geared to all levels and types of developers, reveals how to develop powerful, full-featured Web pages with JavaScript by covering such topics as BOM, DOM, embedded objects, server-side JavaScript (ASP and JScript), and working with XML.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-object-reference
JavaScript Object Reference - GeeksforGeeks
Primitive data types (Number, String, Boolean, null, undefined, and Symbol) are immutable and store single values, while objects are mutable and can store collections of key-value pairs. Primitives are compared by value, whereas objects are compared by reference. To clone an object in JavaScript, you can use various methods such as the spread operator {...obj}, Object.assign({}, obj), or for a deep copy, JSON.parse(JSON.stringify(obj)).
Published   July 23, 2025
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › with
with - JavaScript | MDN - MDN Web Docs - Mozilla
The following with statement specifies that the Math object is the default object. The statements following the with statement refer to the PI property and the cos and sin methods, without specifying an object. JavaScript assumes the Math object for these references.