data types
In JavaScript, data types define what kind of value a variable holds.
JavaScript has two main categories:
✅ Types:
1. Number
let age = 21;
let price = 99.99;
2. String
let name = "Aman";
3. Boolean
let isLoggedIn = true;
4. Undefined
let x;
[Link](x); // undefined
👉 Variable declared but no value assigned.
5. Null
let y = null;
👉 Intentional empty value.
Examples
What is Type Conversion in JavaScript?
Type conversion means changing a value from one data type to
another
Two Types of Type Conversion
1. Implicit Conversion (Automatic)
JavaScript converts types automatically
let result = "5" + 2;
[Link](result); // "52"
Number 2 becomes string → "52"
2. Explicit Conversion (Manual)
You convert types yourself
Common methods:
Number("10") // → 10
String(100) // → "100"
Boolean(1) // → true
More Examples
🔹 String to Number
Number("25") // 25
🔹 Number to String
String(50) // "50"
🔹 To Boolean
Boolean(0) // false
Boolean(1) // true
Boolean("") // false