[go: up one dir, main page]

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

Primitive & Nonprimitive

The document outlines the differences between primitive and non-primitive data types in JavaScript. Primitives are immutable and include types such as String, Number, Boolean, Null, Undefined, and Symbol, while non-primitives are mutable and include Objects, Arrays, Functions, and more. Examples are provided to illustrate each type and their characteristics.

Uploaded by

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

Primitive & Nonprimitive

The document outlines the differences between primitive and non-primitive data types in JavaScript. Primitives are immutable and include types such as String, Number, Boolean, Null, Undefined, and Symbol, while non-primitives are mutable and include Objects, Arrays, Functions, and more. Examples are provided to illustrate each type and their characteristics.

Uploaded by

weirdvirel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Diploma in full-stack web development

*JAVASCRIPT notes by ASP Computer*

“Primitives and non-primitive ”


1) Primitives and non-primitive datatype in JavaScript ?

Primitives:

Primitives are immutable data types. This means that their values
cannot be changed. When you manipulate a primitive, you're
actually creating a new value.

The primitive types in JavaScript are:

String: Represents a sequence of characters, enclosed within


single (''), double ("") or backtick (``) quotes.

Number: Represents numeric data, including integers and


floating-point numbers.

Boolean: Represents a logical entity and can have two values:


true or false.

Null: Represents the intentional absence of any object value.

Undefined: Represents an uninitialized variable or a variable that


has been declared but not assigned any value.

Symbol: Represents a unique identifier.

Example:
let str = "Hello";
let num = 42;
let bool = true;
let n = null;
let u; // undefined
let sym = Symbol("foo");

Non-primitives (Reference types):

Non-primitive data types are mutable and are manipulated by


reference rather than by value. These types are more complex
data structures and are composed of multiple values.

The main non-primitive type in JavaScript is:

Object: Represents a collection of key-value pairs, where keys


are strings (or Symbols) and values can be of any data type,
including other objects.

Example:
let obj = {
name: "John",
age: 30,
isStudent: false
};

Other non-primitive types in JavaScript are derived from


objects, including:

Array: A special type of object used to store multiple values in a


single variable.

Function: A callable object that executes a block of code.

Date: A built-in object for working with dates and times.

And more, such as RegExp, Map, Set, etc.

You might also like