JavaScript Data Types
Dynamic Typing
JavaScript is a dynamically typed language. This means you don't have to specify the data type of a variable when you declare it, and data types are converted automatically as needed during script execution.
Primitive Data Types
JavaScript has 7 primitive data types:
- String: Text data, e.g.,
"Hello" - Number: Integer or floating-point, e.g.,
42,3.14 - BigInt: Integers with arbitrary precision
- Boolean:
trueorfalse - Undefined: A variable that has not been assigned a value
- Null: Intentional absence of any object value
- Symbol: Unique and immutable primitive
The typeof Operator
You can use the typeof operator to find the data type of a
JavaScript variable.
Objects
Objects are collections of key-value pairs. They are the most important data type in JavaScript.
Arrays
Arrays are a special type of object used to store multiple values in a single variable.
const cars = ["Saab", "Volvo", "BMW"];
Summary
- JavaScript variables can hold many data types: numbers, strings, objects and more.
- JavaScript has dynamic types.
- Strings are written with quotes.
- Numbers are written with or without decimals.
- Booleans can only have two values:
trueorfalse.
Quick Quiz
What is the data type of the value 'Hello'?
Enjoying these tutorials?