1. Primitive (Basic) Data Types
These are the most fundamental, predefined data types built directly into a computer language. They store simple, single values directly in memory.
- Integer (int): Stores whole numbers without decimals, both positive and negative.
Example: 42 or -7.
- Floating-Point (float / double): Stores fractional or real numbers containing one or more decimal places.
Example: 3.14 or 0.005.
- Character (char): Stores a single letter, number, punctuation mark, or symbol enclosed in quotes.
Example: 'A' or '$'
- Boolean (bool):Represents logical values and can only be one of two states.
Example: true or false.
**
2.Non-Primitive (Composite) Data Types**
These are more complex structures created by the programmer or provided by the language to group primitive data types together. Instead of storing a value directly, they often store references or memory addresses to where the data is located.
String: A sequence or collection of text characters grouped together. Example: "Hello World".
Array: A collection of elements of the same data type stored in a fixed, sequential order. Example: [10, 20, 30, 40].
Object / Dictionary: A collection of key-value pairs used to store data in structured formats.
Example: {"name": "Alice", "age": 25}.
What is a Data Type?
A data type is the type of data a variable has, like is it a text or is it a number?
The data type we set a variable to affects what we can do with the variable.
For example, if we have two variables of a number data type, with values 3 and 4, we can use the + operator to add them together, and we get 7:
- But, if we store the two values as text string data types instead, as "3" and "4", we get "34" as the result when we use the + operator:
- What data types you have available depends on the programming language you are using, but the most common data types are:
- String (text)
- Integer (whole number)
- Float (decimal number)
- Boolean (true or false)
The 8 JavaScript Data Types