0% found this document useful (0 votes)
6 views2 pages

Understanding JavaScript Primitives and Objects

JavaScript defines seven primitive data types: string, number, boolean, null, undefined, symbol, and bigint, which are immutable values without properties or methods. Additionally, JavaScript allows the creation of objects using various methods, including object literals, constructors, and Object.create(). An object literal is a straightforward way to create an object by defining name:value pairs within curly braces.

Uploaded by

MahenderBandal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Understanding JavaScript Primitives and Objects

JavaScript defines seven primitive data types: string, number, boolean, null, undefined, symbol, and bigint, which are immutable values without properties or methods. Additionally, JavaScript allows the creation of objects using various methods, including object literals, constructors, and Object.create(). An object literal is a straightforward way to create an object by defining name:value pairs within curly braces.

Uploaded by

MahenderBandal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

avaScript Primitives

A primitive value is a value that has no properties or methods.

3.14 is a primitive value

A primitive data type is data that has a primitive value.

JavaScript defines 7 types of primitive data types:

Examples
 string
 number
 boolean
 null
 undefined
 symbol
 bigint

 immutable
 Primitive values are immutable (they are hardcoded and cannot be changed).
 if x = 3.14, you can change the value of x, but you cannot change the value of
3.14.

Value Type Comment

"Hello" string "Hello" is always "He

3.14 number 3.14 is always 3.14

true boolean true is always true

false boolean false is always false


null null (object) null is always null

undefined undefined undefined is always u

let person = {firstName:"John", lastName:"Doe", age:50,


eyeColor:"blue"};
Try it Yourself »

const person = {firstName:"John", lastName:"Doe", age:50,


eyeColor:"blue"};Objects written as name value pairs are similar to:

 Associative arrays in PHP


 Dictionaries in Python
 Hash tables in C
 Hash maps in Java
 Hashes in Ruby and Perl

Creating a JavaScript Object


With JavaScript, you can define and create your own objects.

There are different ways to create new objects:

 Create a single object, using an object literal.


 Create a single object, with the keyword new.
 Define an object constructor, and then create objects of the constructed
type.
 Create an object using [Link]().

Using an Object Literal


This is the easiest way to create a JavaScript Object.

Using an object literal, you both define and create an object in one statement.

An object literal is a list of name:value pairs (like age:50) inside curly braces {}.

The following example creates a new JavaScript object with four properties:

You might also like