JAVASCRIPT

Reference Values



Non-primitive data types are referred to complex structures that can store and organize multiple values.

 

There are 3 types of reference Data Values:

 

1. Object

2. Array

3. Function

 

1. Object:

An object is a collection of key-value pairs, allowing you to create complex data structures and models. Keys (properties) can be strings or symbols, and values can be any data type.

 

Syntax:

let object_variable = {
        key1: value1,
        key2: value2,
        // Additional key-value pairs
	};

 

Example:

let myobject = {
        userName: "Wasif",
        age: 21,
    }

 

2. Array:

An array is an ordered list that can hold multiple values. Each value in the array element is identified by an index, starting from 0.
 

Syntax:

let array_variable = [value1, value2, value3];

 

Example:

let array_name = [value1, value2, value3];

 

3. Function

A function is a block of reusable code that can be invoked with different arguments. Functions can return values and are a fundamental building block in JavaScript.

 

Syntax:

function function_name(paraMeter){
	// code
}

 

Example:

function product(){
		let a = 3;
		let b = 4;
		let product = a * b;
	}

 

Modifying the value through one reference affects all references pointing to the same object..