Q1. What Are Datatypes ?
Data types define the type of value a variable can store. JavaScript supports different types of data such as numbers, strings, objects, and more.
Data types help JavaScript understand how to store and process values.
Data types help JavaScript understand how to store and process values.
Q2. How Many Types of Data Types Exist in JavaScript?
JavaScript has two main categories of data types:
1. Primitive Data Types
2. Non-Primitive (Reference) Data Types
2. Non-Primitive (Reference) Data Types
Q3. What Are Primitive Data Types in JavaScript?
Primitive data types store single values and are immutable.
Types of Primitive Data Types:
Types of Primitive Data Types:
- Number
- String
- Boolean
- Undefined
- Null
- BigInt
- Symbol
Example
let num = 10; // Numberlet name = "John"; // Stringlet isActive = true; // Booleanlet data; // Undefinedlet value = null; // NullQ4. What Are Non-Primitive Data Types?
Non-primitive data types store collections of values or complex data.
Example
Example
These data types store multiple values.
Example
- Object
- Array
- Function
let person = { name: "John", age: 30};
let numbers = [10, 20, 30];These data types store multiple values.
Q5. How Can You Check the Data Type of a Variable?
JavaScript provides the typeof operator to check data types.
Example
Output
Example
let name = "John";console.log(typeof name);Output
string