JavaScript Non-Primitive Data Types Examples
Object:
JavaScript objects are fundamental data structures used to store collections of data. They consist of key-value pairs and can be created using curly braces {}
or the new
keyword. Understanding objects is crucial, as everything in JavaScript is essentially an object.
Object creation:
Using the “object constructor” syntax:
let person = new Object();
Using the “object literal” syntax:
let person = {}; //
Both these methods are correct, though it’s totally your call what to choose. We can also put properties inside an Object.
JavaScript Data Types
JavaScript supports multiple data types. Understanding these data types is fundamental to effective programming. JavaScript data types are broadly categorized into primitive and non-primitive types. The primitive data types include Number, String, Boolean, Null, Undefined, and Symbol. Non-primitive types include Object, Array, and Function. This guide will delve into these data types, providing a comprehensive overview and examples to help you master their usage in JavaScript.
The latest ECMAScript standard defines eight data types Out of which seven data types are Primitive(predefined) and one complex or Non-Primitive.