In JavaScript, every value has a type. This type tells JavaScript what kind of data it is working with, such as numbers, text, or true/false values.
Data types are important because they decide what operations you can perform on a value. For example, you can add numbers, but you cannot add numbers to text in the same way.
Understanding data types helps you write correct programs and avoid common mistakes.
Main Data Types in JavaScript
- Number – for numeric values
- String – for text values
- Boolean – for true or false
- Undefined – when a variable has no value
- Null – when a variable is intentionally empty
These are the most common data types used in beginner programs.
In this example, age is a number and name is a string. JavaScript automatically understands the type of each value.
This shows that JavaScript is a dynamically typed language, which means you do not need to specify the data type manually.
The boolean data type has only two values: true and false. It is commonly used in conditions and decision-making statements.
In this example, result is undefined because no value is assigned, while score is null because it is intentionally empty.
Understanding the difference between undefined and null is important for handling data correctly in real programs.