0% found this document useful (0 votes)
4 views3 pages

JavaScript TypeScript Notes

The document provides an overview of variables and data types in JavaScript and TypeScript, detailing variable declarations using var, let, and const, along with their differences. It covers various data types including Number, String, Boolean, and more, as well as concepts like arrays, objects, type inference, and union types. Additionally, it highlights common beginner mistakes and important interview questions related to the topic.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

JavaScript TypeScript Notes

The document provides an overview of variables and data types in JavaScript and TypeScript, detailing variable declarations using var, let, and const, along with their differences. It covers various data types including Number, String, Boolean, and more, as well as concepts like arrays, objects, type inference, and union types. Additionally, it highlights common beginner mistakes and important interview questions related to the topic.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]

You might also like