JavaScript & TypeScript Notes — Variables and Data Types
1. What is a Variable?
A variable is used to store data.
let name = "Gnanendhar";
2. Variable Keywords
var - Old way of declaring variables.
var age = 20;
let - Modern and recommended.
let city = "Nellore";
const - Used for fixed values.
const pi = 3.14;
3. Difference Between var, let, const
Feature var let const
Reassign Yes Yes No
Redeclare Yes No No
Scope Function Block Block
Modern Usage No Yes Yes
4. Data Types
Number
let age: number = 21;
String
let name: string = "Reddy";
Boolean
let isPassed: boolean = true;
Undefined
let data;
Null
let phone = null;
BigInt
let bigNumber = 12345678901234567890n;
Symbol
let id = Symbol("id");
5. Arrays
let fruits: string[] = ["Apple", "Mango"];
6. Objects
let student = { name: "Reddy", age: 21 };
7. Type Inference
let age = 20;
TypeScript automatically detects the type.
8. Any Type
let data: any = 10;
9. Union Types
let value: string | number;
10. Type Conversion
Number("123")
String(100)
11. typeof Operator
[Link](typeof age);
12. Practice Example
let studentName: string = "Reddy";
let age: number = 21;
let isStudent: boolean = true;
13. Common Beginner Mistakes
■ Let age: number = 20;
■ let age: number = 20;
14. Important Interview Questions
• Difference between let and const
• What is TypeScript?
• What is Type Inference?
15. VS Code Commands
tsc [Link]
node [Link]