Skip to main 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 →

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir