Skip to content

JavaScript Data Types

JavaScript is a Dynamically Typed language. This means you don't need to specify the type of a variable, and the same variable can hold different types at different times.

let x;           // Now x is undefined
x = 5;           // Now x is a Number
x = "Vishnu";    // Now x is a String

The 8 Types in JavaScript

1. Primitive Types (Basic)

  1. String: Textual data (e.g., "Hello").
  2. Number: Both integers and floats (e.g., 10, 3.14).
  3. BigInt: For very large integers.
  4. Boolean: true or false.
  5. Undefined: A variable that has not been assigned a value.
  6. Null: Represents an intentional "empty" value.
  7. Symbol: A unique and immutable identifier.

2. Complex Types

  1. Object: Used to store collections of data. (Arrays and Functions are also technically Objects).

The typeof Operator

You can use typeof to find out what type of data is stored in a variable.

typeof "John"   // returns "string"
typeof 3.14     // returns "number"
typeof true     // returns "boolean"
typeof {name:'John'} // returns "object"

The Null Bug

In JavaScript, typeof null returns "object". This is a famous bug from the original version of JS that was never fixed to keep the web compatible.


← Back: Variables | Next: Functions →