Web Analytics

JavaScript Data Types

Beginner ~12 min read

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.

HTML
CSS
JS

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: true or false
  • 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.

HTML
CSS
JS

Objects

Objects are collections of key-value pairs. They are the most important data type in JavaScript.

HTML
CSS
JS

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: true or false.

Quick Quiz

What is the data type of the value 'Hello'?

A
Number
B
Boolean
C
String
D
Object