Docsity

Master JavaScript Variables & DOM Manipulation: Complete Frontend Guide (let vs const, Co, Schemes and Mind Maps of Computer Science

Toggle sidebar
bg1
JavaScript & DOM Manipulation
Complete Professional Study & Exam Preparation Notes
Step 1: Variables (Data ko Save Karna)
Concept: Variable ko aap ek 'Khali Dibba' (Empty Box) samajh lein. Is dibbe ka kaam yeh hai ke yeh aap ka data apne
andar sambhal kar rakhta hai taake aap use baad mein program mein kahin bhi istemal kar sakein. JavaScript mein variable
banane ke liye hum buniyadi taur par do major keywords ka istemal karte hain: let aur const.
1. let (Mutable - Badla Ja Sakne Wala)
Farz karein ek game chal rahi hai aur user ka score abhi 0 hai. Baad mein jab woh behtar khelega to score badh kar 10 ho
jata hai. Aisi situation mein hum let ka use karte hain kyunki is ka saman (value) badalna allowed hota hai.
let score = 0; // Dibbe ka naam 'score' hai aur andar '0' rakha hai.
score = 10; // Ab hum ne score badal kar 10 kar diya. (This is completely Allowed)
2. const (Immutable - Locked Value)
Kuch cheezein pure program mein aisi hoti hain jo kabhi nahi badaltein, jaise aap ki date of birth ya pi (Ļ€) ki fixed
mathematical value. Inke liye hum const use karte hain taake koi galti se bhi value change na kar sake.
const pi = 3.14; // Yeh value ab completely freeze aur lock ho gayi hai.
pi = 5; // Error: Assignment to constant variable! (Not Allowed)
Professional Rule of Thumb: Senior aur professional web developers ka ek sunehri asool hota hai: 'Hamesha const ka istemal
karo, jab tak aap ko pakka pata na ho ke yeh value aage chal kar badle gi!' Is se bugs aane ke chances khatam ho jaate hain.
Commercial & Production-Level Examples of const:
Category Real-World Application Scenario Code Reference Syntax
Settings Website configuration limits jo backend ya security
ke liye fix rehti hain.
const maxLoginAttempts = 5;
API Link Website ka main link ya production server endpoint
url.
const apiURL = "https://mywebsite.com";
Fixed Info User ka original mulk ya aisi unique ID jo badal nahi
sakti.
const country = "Pakistan";
Step 2: Output Dekhna (The Developer's Glasses)
Ab hum ne data ko dibbe mein save to kar diya, lekin use screen par verify kaise karna hai? Us ke liye hum console.log() ka
istemal karte hain. Yeh samajh lein ke yeh JavaScript ka ek 'Chashma' hai jo developers ko live environment mein dibbe ke
andar ka asal saman aur value dikhata hai.
JavaScript & DOM Integration Masterclass | Student Study Edition Page 1 of 3
pf3

Partial preview of the text

Download Master JavaScript Variables & DOM Manipulation: Complete Frontend Guide (let vs const, Co and more Schemes and Mind Maps Computer Science in PDF only on Docsity!

JavaScript & DOM Manipulation

Complete Professional Study & Exam Preparation Notes

Step 1: Variables (Data ko Save Karna)

Concept: Variable ko aap ek 'Khali Dibba' (Empty Box) samajh lein. Is dibbe ka kaam yeh hai ke yeh aap ka data apne andar sambhal kar rakhta hai taake aap use baad mein program mein kahin bhi istemal kar sakein. JavaScript mein variable banane ke liye hum buniyadi taur par do major keywords ka istemal karte hain: let aur const.

1. let (Mutable - Badla Ja Sakne Wala)

Farz karein ek game chal rahi hai aur user ka score abhi 0 hai. Baad mein jab woh behtar khelega to score badh kar 10 ho jata hai. Aisi situation mein hum let ka use karte hain kyunki is ka saman (value) badalna allowed hota hai.

let score = 0; // Dibbe ka naam 'score' hai aur andar '0' rakha hai. score = 10; // Ab hum ne score badal kar 10 kar diya. (This is completely Allowed)

2. const (Immutable - Locked Value)

Kuch cheezein pure program mein aisi hoti hain jo kabhi nahi badaltein, jaise aap ki date of birth ya pi (Ļ€) ki fixed mathematical value. Inke liye hum const use karte hain taake koi galti se bhi value change na kar sake.

const pi = 3.14; // Yeh value ab completely freeze aur lock ho gayi hai. pi = 5; // Error: Assignment to constant variable! (Not Allowed)

Professional Rule of Thumb: Senior aur professional web developers ka ek sunehri asool hota hai: 'Hamesha const ka istemal karo, jab tak aap ko pakka pata na ho ke yeh value aage chal kar badle gi!' Is se bugs aane ke chances khatam ho jaate hain.

Commercial & Production-Level Examples of const:

Category Real-World Application Scenario Code Reference Syntax

Settings Website configuration limits jo backend ya security ke liye fix rehti hain.

const maxLoginAttempts = 5;

API Link Website ka main link ya production server endpoint url.

const apiURL = "https://mywebsite.com";

Fixed Info User ka original mulk ya aisi unique ID jo badal nahi sakti.

const country = "Pakistan";

Step 2: Output Dekhna (The Developer's Glasses)

Ab hum ne data ko dibbe mein save to kar diya, lekin use screen par verify kaise karna hai? Us ke liye hum console.log() ka istemal karte hain. Yeh samajh lein ke yeh JavaScript ka ek 'Chashma' hai jo developers ko live environment mein dibbe ke andar ka asal saman aur value dikhata hai.

let studentName = "Ali"; // Screen/Console par output check karne ke liye: console.log (studentName); // Screen pe Output aayega: Ali