JavaScript non-Primitive Data Type

JavaScript non-Primitive Data Type


JavaScript non- Primitive Data Type
Primitive data types: those not defined in terms of other data types. In other words we can say that in-built data type. Most programming languages provide a set of primitive data types.
JavaScript non-primitive data types are as follows:
  • Object 
  • Array
JavaScript Object data type
 In Javascript, An Object is a non- primitive data type. Object is an entity having properties and methods. Everything is an object in javascript.
How to create an object in javascript:
  • Using Constructor Function to define an object:
// Create an empty generic object
var obj1 = new Object();
 
// Create a user defined object
var mycar1 = new Car();
  • sing Literal equations to define an object:
// An empty object
var square1 = {};
 
// Here a and b are keys and
// 10 and 40 are values
var circle = {a: 10, b: 40};
Example
Output
JavaScript Array data type
In JavaScript, An Array is a non- primitive data type. You can store more than one element under a single name with the help of an array.
Ways to declare a single dimensional array:
// Call it with no arguments
var x = new Array();
 
// Call it with single numeric argument
var y = new Array(10);
// Explicitly specify two or
// more array elements
var z = new Array(1, 2, 3, "Hello World! Welcome to WDH.");
Example
Output