JS Data types

JavaScript provides different data types to hold different types of values. These data types are categorized into two main types:

1. primitive data types

2. non-primitive (reference) data types.

table style="width: 100%; border-collapse: collapse; margin-bottom: 20px;"> Primitive Data Types Data Type Description Example Code Example String Represents a sequence of characters. "hello" var name = "Rahul"; Number Represents numeric values. 100 var age = 40; Boolean Represents a boolean value, either true or false. true or false var isStudent = true; Undefined Represents a variable that has been declared but not assigned a value. undefined var x; console.log(x); Null Represents a null value, meaning no value at all. null var person = null;
Non-Primitive (Reference) Data Types
Data Type Description Example Code Example
Object Represents an instance through which we can access members (properties and methods). { firstName: "John", lastName: "Doe", age: 25 } var person = { firstName: "John", lastName: "Doe", age: 25 };
Array Represents a group of similar values. ["Apple", "Banana", "Cherry"] var fruits = ["Apple", "Banana", "Cherry"];
RegExp Represents a regular expression used for pattern matching. /ab+c/ var pattern = /ab+c/;

Dynamic Typing

JavaScript is a dynamically typed language, meaning you don't need to specify the type of a variable when you declare it. The type of the variable is determined dynamically based on the value assigned to it. This allows a variable to hold any type of value, such as numbers, strings, etc.