Reference Types in Javascript .

Reference Types in Javascript .

The Easy Way !

What are Reference types in javascript ?

Reference Types :

A reference type can contain other values . Since the contents of a reference type can not fit in the fixed amount of memory available for a variable, the "in-memory" value of a reference type is the reference itself (a memory address).

Reference types are also known as: complex types or container types.

Reference types can be of any length -- they do not have a fixed size. The same is true of arrays : an array can have any number of elements. Similarly, a function can contain any amount of JavaScript code. Since these types do not have a fixed size, their values cannot be stored directly in the eight bytes of memory associated with each variable. Instead, the variable stores a reference to the value. Typically, this reference is some form of pointer or memory address. It is not the data value itself, but it tells the variable where to look to find the value.

For Example:

var a = [5,4,12];  // Initialize a variable to refer to an array
var b = a;          // Copy that reference into a new variable
a[0] = 10;        // Modify the array using the original reference, making the first index become 10
alert(b);          // Display the changed array [10,4,12] using the new reference..

Reference Types are below

  • Arrays
  • Object Literals
  • Functions
  • Dates
  • Anything else you can store in javascript .

Checkout my other articles Good Read ?, Like, Share, Clap , Engage Thank You .