Data Types in JavaScript
In JavaScript, data types define the type of value that a variable can store. When we create variables in a program, those variables hold different kinds of data such as numbers, text, or logical values. JavaScript uses data types to understand how the stored data should be processed.
Understanding data types is very important because they help developers perform correct operations on data. For example, adding two numbers is different from combining two text strings.
What are Data Types?
A data type describes the type of value stored in a variable. JavaScript automatically determines the type of data when a value is assigned to a variable. This behavior is called dynamic typing.
In the example above, JavaScript automatically understands that 25 is a number and "John" is a string.
Types of Data Types in JavaScript
JavaScript data types are generally divided into two main categories:
- Primitive Data Types
- Non-Primitive (Reference) Data Types
Primitive Data Types
Primitive data types store single values and are the most basic types of data in JavaScript.
1. String
A string represents textual data. Strings are written inside single quotes (' '), double quotes (" "), or backticks.
Strings are commonly used for names, messages, or any textual information.
2. Number
The number data type represents numeric values. JavaScript uses the same type for both integers and decimal numbers.
3. Boolean
The boolean data type represents logical values. It can only have two possible values: true or false.
Booleans are widely used in conditions and decision-making statements.
4. Undefined
A variable that has been declared but not assigned any value automatically has the undefined data type.
5. Null
The null data type represents an intentional absence of value. It means the variable is empty.
6. BigInt
BigInt is used to store very large integers that exceed the limit of the normal number data type.
7. Symbol
The Symbol data type is used to create unique identifiers. It is mostly used in advanced JavaScript programming.
Non-Primitive Data Types
Non-primitive data types are more complex and can store collections of values or more detailed entities.
1. Object
Objects store data in key-value pairs. They are widely used in JavaScript to represent real-world entities.
2. Array
Arrays are used to store multiple values in a single variable.
Checking Data Type Using typeof
JavaScript provides the typeof operator to check the type of a variable.
Output:
Conclusion
Data types are fundamental to understanding how JavaScript works. They define the kind of data stored in variables and determine how operations are performed on that data.
JavaScript includes several primitive data types such as string, number, boolean, undefined, null, bigint, and symbol. It also supports complex non-primitive types such as objects and arrays.
A clear understanding of data types helps developers write efficient and error-free programs. In the next tutorial, we will learn about JavaScript Operators and how they are used to perform operations on variables and values.

