What is Primitives
Primitives are the basic building blocks of JavaScript and represent immutable data. They are not objects and do not have methods (although JavaScript temporarily wraps them in objects to allow method-like behavior).
Types of Primitives
1. Boolean
2. Null
3. Undefined
4. Number
5. String
6. Symbol
7. BigInt
1. Boolean
Boolean is a primitive data type that can have one of two values : true or false. It is used to represent a logical value.
Example
2. Null
Null is a primitive data type that represents the intentional absence of any object value. It is used to represent a value that does not exist.
Example
3. Undefined
Undefined is a primitive data type that represents an uninitialized variable or an expression that has not been assigned a value.
Example
4. Number
Number is a primitive data type that represents a numeric value. It can be either an integer or a floating-point number.
Example
5. String
String is a primitive data type that represents a sequence of characters . It can be enclosed in single quotes or double quotes.
Example
let str = "Hi This is me!!"
6. Symbol
Symbol is a primitive data type that represents a unique and immutable value. It is used to create unique identifiers for objects.
Example
let sym = Symbol('unique');
7. BigInt
BigInt is a primitive data type that represents a large integer value . It is used to represent integers that are too large to be represented by the Number data type.
Example
let big =123456789123;
Objects
Objects are a composite data type that can hold multiple values. They are used to represent complex data structures and are a fundamental data type in JavaScript.
Objects are defined using the object literal
syntax, which consists of a set of key-value pairs enclosed in curly braces.
Objects in JavaScript are collections of key-value pairs. They can store multiple values and are mutable.
Plain Objects: Defined using {} or new Object(). Example:
Example
let obj = {
name: "John",
age: 30,
city: "New York"
}