Repository navigation
Expand file tree
/
Copy pathJavaScript_Complete_Study_Notebook.html
More file actions
1571 lines (1414 loc) · 123 KB
/
Copy pathJavaScript_Complete_Study_Notebook.html
File metadata and controls
1571 lines (1414 loc) · 123 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript — The Complete Study Notebook</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&family=Inter:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&family=Caveat:wght@600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root{
--bg:#f4f7ff;--paper:#ffffff;--paper2:#fafbff;
--primary:#6c63ff;--secondary:#ff6584;--mint:#43c6ac;--orange:#f7971e;--purple:#e040fb;--cyan:#00bcd4;
--text:#2d2d48;--muted:#7b7b9d;--border:#e4e8ff;
--shadow:0 8px 30px rgba(108,99,255,.12);--shadow-card:0 10px 35px rgba(108,99,255,.14);
}
*{margin:0;padding:0;box-sizing:border-box;}
html{scroll-behavior:smooth;}
body{font-family:'Inter',sans-serif;color:var(--text);
background:radial-gradient(circle at 15% 10%, rgba(108,99,255,.10), transparent 40%),
radial-gradient(circle at 85% 25%, rgba(255,101,132,.10), transparent 40%),
radial-gradient(circle at 30% 80%, rgba(67,198,172,.10), transparent 40%),
linear-gradient(135deg,#eef2ff 0%,#fdfbff 50%,#f3f7ff 100%);
background-attachment:fixed;position:relative;overflow-x:hidden;}
body::before{content:"";position:fixed;inset:0;
background-image:linear-gradient(rgba(108,99,255,.05) 1px, transparent 1px),linear-gradient(90deg, rgba(108,99,255,.05) 1px, transparent 1px);
background-size:32px 32px;pointer-events:none;z-index:0;}
::selection{background:var(--primary);color:#fff;}
::-webkit-scrollbar{width:10px;}
::-webkit-scrollbar-track{background:var(--bg);}
::-webkit-scrollbar-thumb{background:linear-gradient(var(--primary),var(--secondary));border-radius:10px;}
h1,h2,h3,h4{font-family:'Poppins',sans-serif;}
.mono{font-family:'JetBrains Mono',monospace;}
.hand{font-family:'Caveat',cursive;}
.sg{font-family:'Space Grotesk',sans-serif;}
a{color:var(--primary);}
#progress{position:fixed;top:0;left:0;height:4px;background:linear-gradient(90deg,var(--primary),var(--secondary),var(--orange));z-index:9999;width:0%;transition:width .1s;}
nav{position:sticky;top:0;z-index:900;display:flex;align-items:center;justify-content:space-between;padding:14px 22px;
background:rgba(255,255,255,.65);backdrop-filter:blur(20px);border-bottom:1px solid rgba(255,255,255,.5);box-shadow:var(--shadow);}
.brand{display:flex;align-items:center;gap:10px;font-weight:700;font-size:1.05rem;background:linear-gradient(90deg,var(--primary),var(--secondary));-webkit-background-clip:text;background-clip:text;color:transparent;flex-shrink:0;}
.navlinks{display:flex;gap:14px;overflow-x:auto;max-width:52vw;scrollbar-width:none;}
.navlinks::-webkit-scrollbar{display:none;}
.navlinks a{white-space:nowrap;font-size:.78rem;font-weight:600;color:var(--muted);text-decoration:none;padding:6px 10px;border-radius:20px;transition:.25s;}
.navlinks a:hover{color:#fff;background:linear-gradient(90deg,var(--primary),var(--secondary));}
#searchBox{padding:7px 14px;border-radius:20px;border:1px solid var(--border);font-family:'Inter';font-size:.78rem;outline:none;width:130px;background:rgba(255,255,255,.7);}
.navRight{display:flex;gap:8px;align-items:center;flex-shrink:0;}
#themeBtn{cursor:pointer;border:none;background:linear-gradient(135deg,var(--primary),var(--purple));color:#fff;width:32px;height:32px;border-radius:50%;font-size:1rem;box-shadow:var(--shadow);}
.wrap{max-width:1180px;margin:0 auto;padding:0 24px;position:relative;z-index:1;}
section{padding:80px 0;}
.cover{min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;
background:linear-gradient(135deg,#1a1a2e,#16213e,#0f3460);color:#fff;position:relative;overflow:hidden;padding:40px 20px;}
.blob{position:absolute;border-radius:50%;filter:blur(80px);opacity:.55;animation:float 9s ease-in-out infinite;}
.b1{width:380px;height:380px;background:var(--primary);top:-100px;left:-100px;}
.b2{width:320px;height:320px;background:var(--secondary);bottom:-80px;right:-60px;animation-delay:1.5s;}
.b3{width:260px;height:260px;background:var(--mint);top:40%;right:15%;animation-delay:3s;}
@keyframes float{0%,100%{transform:translateY(0) scale(1);}50%{transform:translateY(-30px) scale(1.08);}}
.sparkle{position:absolute;color:#fff;opacity:.7;animation:twinkle 2.4s ease-in-out infinite;}
@keyframes twinkle{0%,100%{opacity:.2;transform:scale(.8);}50%{opacity:1;transform:scale(1.2);}}
.cover-badge{display:inline-flex;align-items:center;gap:8px;background:rgba(255,255,255,.12);border:1px solid rgba(255,255,255,.25);padding:8px 18px;border-radius:30px;font-size:.8rem;margin-bottom:26px;backdrop-filter:blur(10px);}
.cover h1{font-size:clamp(2.6rem,7vw,5.2rem);font-weight:800;line-height:1.05;background:linear-gradient(90deg,#fff,#f7e98e,#ffd2e5);-webkit-background-clip:text;background-clip:text;color:transparent;margin-bottom:18px;}
.cover p.sub{font-size:1.1rem;color:#c9cbe8;max-width:680px;margin-bottom:30px;}
.chips{display:flex;flex-wrap:wrap;gap:10px;justify-content:center;margin-bottom:34px;}
.chip{padding:8px 16px;border-radius:20px;font-size:.76rem;font-weight:600;background:rgba(255,255,255,.1);border:1px solid rgba(255,255,255,.25);color:#eef;backdrop-filter:blur(6px);}
.cta{display:inline-flex;align-items:center;gap:10px;padding:15px 34px;border-radius:40px;background:linear-gradient(90deg,var(--primary),var(--secondary));color:#fff;font-weight:700;text-decoration:none;box-shadow:0 10px 30px rgba(108,99,255,.5);transition:.3s;border:2px solid transparent;}
.cta:hover{transform:translateY(-3px) scale(1.03);box-shadow:0 14px 40px rgba(255,101,132,.5);}
.meta-row{display:flex;gap:26px;margin-top:34px;flex-wrap:wrap;justify-content:center;color:#c9cbe8;font-size:.82rem;}
.scrollcue{position:absolute;bottom:26px;left:50%;transform:translateX(-50%);color:#c9cbe8;font-size:.75rem;animation:bounce 1.8s infinite;}
@keyframes bounce{0%,100%{transform:translate(-50%,0);}50%{transform:translate(-50%,8px);}}
.eyebrow{display:inline-block;font-size:.7rem;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:var(--primary);background:rgba(108,99,255,.1);padding:5px 14px;border-radius:20px;margin-bottom:14px;}
.stitle{font-size:clamp(1.6rem,4vw,2.4rem);font-weight:800;margin-bottom:10px;background:linear-gradient(90deg,var(--text),var(--primary));-webkit-background-clip:text;background-clip:text;color:transparent;}
.sdesc{color:var(--muted);max-width:720px;margin-bottom:38px;font-size:.98rem;}
.card{background:rgba(255,255,255,.65);backdrop-filter:blur(20px);border:1px solid rgba(255,255,255,.5);border-radius:22px;box-shadow:var(--shadow-card);padding:26px;transition:.35s;}
.card:hover{transform:translateY(-5px);box-shadow:0 18px 45px rgba(108,99,255,.22);}
.grid{display:grid;gap:20px;}
.g2{grid-template-columns:repeat(auto-fit,minmax(280px,1fr));}
.g3{grid-template-columns:repeat(auto-fit,minmax(230px,1fr));}
.g4{grid-template-columns:repeat(auto-fit,minmax(200px,1fr));}
.toc-item{display:flex;align-items:center;gap:12px;padding:12px 16px;text-decoration:none;color:var(--text);}
.toc-num{font-family:'JetBrains Mono';font-weight:700;color:var(--primary);font-size:.8rem;width:34px;flex-shrink:0;}
.toc-item span.t{font-weight:600;font-size:.88rem;}
pre{background:#1e1e2e;color:#d8d8ff;padding:16px 18px;border-radius:14px;overflow-x:auto;font-family:'JetBrains Mono';font-size:.8rem;line-height:1.65;position:relative;box-shadow:var(--shadow);margin:10px 0;}
pre .cm{color:#8888aa;}pre .kw{color:#ff6584;}pre .fn{color:#43c6ac;}pre .st{color:#f7971e;}
.copybtn{position:absolute;top:10px;right:10px;background:rgba(255,255,255,.1);border:1px solid rgba(255,255,255,.2);color:#fff;font-size:.65rem;padding:4px 10px;border-radius:8px;cursor:pointer;}
.box{border-radius:16px;padding:16px 20px;margin:12px 0;border-left:5px solid;position:relative;font-size:.9rem;}
.box h4{margin-bottom:6px;font-size:.88rem;display:flex;align-items:center;gap:8px;}
.box.important{background:rgba(255,101,132,.08);border-color:var(--secondary);}
.box.remember{background:rgba(108,99,255,.08);border-color:var(--primary);}
.box.tip{background:rgba(67,198,172,.08);border-color:var(--mint);}
.box.example{background:rgba(0,188,212,.08);border-color:var(--cyan);}
.box.definition{background:rgba(224,64,251,.08);border-color:var(--purple);}
.box.formula{background:rgba(247,151,30,.08);border-color:var(--orange);}
.box.warning{background:rgba(255,101,132,.12);border-color:#ff3b5c;}
.box.exam{background:rgba(108,99,255,.1);border-color:var(--primary);}
.box.interview{background:rgba(67,198,172,.1);border-color:var(--mint);}
.box.shortcut{background:rgba(247,151,30,.1);border-color:var(--orange);}
.box.dyk{background:rgba(224,64,251,.1);border-color:var(--purple);}
.sticky{background:#fff3b0;padding:16px;border-radius:4px 4px 40px 4px;box-shadow:2px 4px 10px rgba(0,0,0,.15);transform:rotate(-2deg);font-family:'Caveat',cursive;font-size:1.1rem;}
.sticky.pink{background:#ffd6e7;transform:rotate(2deg);}
.sticky.mint{background:#d3f8e2;transform:rotate(-1deg);}
.sticky.blue{background:#d6e8ff;transform:rotate(1.5deg);}
table{width:100%;border-collapse:collapse;font-size:.86rem;}
th,td{padding:11px 13px;text-align:left;border-bottom:1px solid var(--border);}
th{background:linear-gradient(90deg,rgba(108,99,255,.12),rgba(255,101,132,.08));font-weight:700;font-family:'Poppins';}
tr:hover td{background:rgba(108,99,255,.04);}
.flash{perspective:1200px;height:150px;cursor:pointer;}
.flash-inner{position:relative;width:100%;height:100%;transition:transform .6s;transform-style:preserve-3d;}
.flash.flip .flash-inner{transform:rotateY(180deg);}
.flash-face{position:absolute;inset:0;backface-visibility:hidden;border-radius:18px;display:flex;align-items:center;justify-content:center;text-align:center;padding:14px;font-weight:600;font-size:.86rem;}
.flash-front{background:linear-gradient(135deg,var(--primary),var(--purple));color:#fff;}
.flash-back{background:linear-gradient(135deg,var(--mint),var(--cyan));color:#fff;transform:rotateY(180deg);font-size:.78rem;}
.acc{border:1px solid var(--border);border-radius:14px;margin-bottom:10px;overflow:hidden;background:rgba(255,255,255,.6);}
.acc-h{padding:14px 18px;cursor:pointer;font-weight:600;display:flex;justify-content:space-between;align-items:center;font-size:.9rem;}
.acc-body{max-height:0;overflow:hidden;transition:max-height .35s ease;padding:0 18px;font-size:.86rem;color:var(--muted);}
.acc.open .acc-body{max-height:900px;padding:0 18px 16px;}
.acc.open .acc-arrow{transform:rotate(180deg);}
.acc-arrow{transition:.3s;flex-shrink:0;}
.tabs{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:20px;}
.tab-btn{padding:8px 16px;border-radius:20px;border:1px solid var(--border);background:#fff;font-weight:600;font-size:.8rem;cursor:pointer;}
.tab-btn.active{background:linear-gradient(90deg,var(--primary),var(--secondary));color:#fff;border-color:transparent;}
.tab-panel{display:none;}
.tab-panel.active{display:block;}
.timeline{position:relative;padding-left:34px;}
.timeline::before{content:"";position:absolute;left:9px;top:0;bottom:0;width:3px;background:linear-gradient(var(--primary),var(--secondary));}
.tl-item{position:relative;margin-bottom:22px;}
.tl-item::before{content:"";position:absolute;left:-30px;top:4px;width:16px;height:16px;border-radius:50%;background:#fff;border:4px solid var(--primary);}
.tl-year{font-family:'Space Grotesk';font-weight:700;color:var(--primary);}
footer{padding:60px 0 40px;text-align:center;color:var(--muted);font-size:.85rem;}
.divider{height:2px;background:linear-gradient(90deg,transparent,var(--border),transparent);margin:50px 0;}
#toTop{position:fixed;bottom:26px;right:26px;width:46px;height:46px;border-radius:50%;background:linear-gradient(135deg,var(--primary),var(--secondary));color:#fff;border:none;box-shadow:var(--shadow-card);cursor:pointer;font-size:1.1rem;opacity:0;transition:.3s;z-index:800;}
#toTop.show{opacity:1;}
.reveal{opacity:0;transform:translateY(24px);transition:opacity .7s ease, transform .7s ease;}
.reveal.in{opacity:1;transform:translateY(0);}
.pill{display:inline-block;padding:4px 12px;border-radius:14px;font-size:.68rem;font-weight:700;background:rgba(108,99,255,.12);color:var(--primary);margin-bottom:10px;}
.icon-wrap{width:42px;height:42px;border-radius:12px;display:flex;align-items:center;justify-content:center;margin-bottom:10px;background:linear-gradient(135deg,var(--primary),var(--secondary));color:#fff;}
.subhead{font-size:1.05rem;font-weight:700;margin:26px 0 10px;color:var(--text);display:flex;align-items:center;gap:8px;}
.ascii{background:#12121e;color:#8ee6b8;padding:14px 18px;border-radius:12px;font-family:'JetBrains Mono';font-size:.72rem;line-height:1.5;overflow-x:auto;white-space:pre;}
.dark body{background:#0f1226;}
@media(max-width:768px){.navlinks{display:none;}section{padding:56px 0;}}
</style>
</head>
<body>
<div id="progress"></div>
<nav>
<div class="brand">🟨 JavaScript</div>
<div class="navlinks">
<a href="#basics">Basics</a><a href="#datatypes">Data Types</a><a href="#functions">Functions</a>
<a href="#objects">Objects</a><a href="#arrays">Arrays</a><a href="#async">Async</a>
<a href="#advanced">Advanced</a><a href="#oop">OOP/FP</a><a href="#patterns">Patterns</a>
<a href="#security">Security</a><a href="#capstone">Capstone</a>
<a href="#cheatsheet">Cheatsheet</a><a href="#interviewq">Interview</a><a href="#mistakes">Mistakes</a>
</div>
<div class="navRight">
<input id="searchBox" placeholder="Search...">
<button id="themeBtn" onclick="document.documentElement.classList.toggle('dark')">🌙</button>
</div>
</nav>
<!-- COVER -->
<section class="cover" id="cover">
<div class="blob b1"></div><div class="blob b2"></div><div class="blob b3"></div>
<div class="sparkle" style="top:15%;left:20%;">✦</div>
<div class="sparkle" style="top:30%;right:18%;animation-delay:.6s;">✧</div>
<div class="sparkle" style="bottom:25%;left:30%;animation-delay:1.2s;">✦</div>
<div class="cover-badge">📘 The Complete Notebook · Beginner → Professional</div>
<h1>JavaScript</h1>
<p class="sub">Variables se leke Event Loop, Closures, Prototypes, Async, OOP, Design Patterns aur real projects tak — sab kuch ek jagah, Hindi + English + Hinglish me, gehraai (depth) ke saath.</p>
<div class="chips">
<span class="chip">🧠 Engine Internals</span><span class="chip">🔒 Closures & Scope</span>
<span class="chip">⚡ Event Loop</span><span class="chip">🧩 Prototypes & OOP</span>
<span class="chip">🎯 Design Patterns</span><span class="chip">🚀 Interview Ready</span>
</div>
<a href="#intro" class="cta">🚀 Start Learning</a>
<div class="meta-row">
<span>⏱️ Reading time: ~140 min</span><span>🎯 Zero → Professional</span><span>📚 Subject: JavaScript / ECMAScript</span>
</div>
<div class="scrollcue">↓ scroll to explore ↓</div>
</section>
<div class="wrap">
<!-- TOC -->
<section id="toc">
<span class="eyebrow">Navigate</span>
<h2 class="stitle">Table of Contents</h2>
<p class="sdesc">Poora JavaScript ek hi notebook me — jaha chaho waha jump karo.</p>
<div class="card grid g3">
<a class="toc-item" href="#intro"><span class="toc-num">01</span><span class="t">Introduction & Engines</span></a>
<a class="toc-item" href="#setup"><span class="toc-num">02</span><span class="t">Setup (Node, npm, VS Code)</span></a>
<a class="toc-item" href="#basics"><span class="toc-num">03</span><span class="t">Variables & Basics</span></a>
<a class="toc-item" href="#datatypes"><span class="toc-num">04</span><span class="t">Data Types</span></a>
<a class="toc-item" href="#operators"><span class="toc-num">05</span><span class="t">Operators & Coercion</span></a>
<a class="toc-item" href="#control"><span class="toc-num">06</span><span class="t">Control Flow</span></a>
<a class="toc-item" href="#functions"><span class="toc-num">07</span><span class="t">Functions & Closures</span></a>
<a class="toc-item" href="#objects"><span class="toc-num">08</span><span class="t">Objects, this, Prototypes</span></a>
<a class="toc-item" href="#arrays"><span class="toc-num">09</span><span class="t">Arrays (all methods)</span></a>
<a class="toc-item" href="#strings"><span class="toc-num">10</span><span class="t">Strings, Numbers, Dates, Math, JSON</span></a>
<a class="toc-item" href="#errors"><span class="toc-num">11</span><span class="t">Error Handling</span></a>
<a class="toc-item" href="#modules"><span class="toc-num">12</span><span class="t">Modules</span></a>
<a class="toc-item" href="#dom"><span class="toc-num">13</span><span class="t">DOM & Events & Browser APIs</span></a>
<a class="toc-item" href="#storage"><span class="toc-num">14</span><span class="t">Storage</span></a>
<a class="toc-item" href="#async"><span class="toc-num">15</span><span class="t">Async JS & Event Loop</span></a>
<a class="toc-item" href="#oop"><span class="toc-num">16</span><span class="t">OOP in JavaScript</span></a>
<a class="toc-item" href="#fp"><span class="toc-num">17</span><span class="t">Functional Programming</span></a>
<a class="toc-item" href="#advanced"><span class="toc-num">18</span><span class="t">Advanced JS (Hoisting, Scope, GC, Proxy...)</span></a>
<a class="toc-item" href="#patterns"><span class="toc-num">19</span><span class="t">Design Patterns & SOLID</span></a>
<a class="toc-item" href="#cleanperf"><span class="toc-num">20</span><span class="t">Clean Code & Performance</span></a>
<a class="toc-item" href="#security"><span class="toc-num">21</span><span class="t">Security</span></a>
<a class="toc-item" href="#testing"><span class="toc-num">22</span><span class="t">Testing</span></a>
<a class="toc-item" href="#node"><span class="toc-num">23</span><span class="t">Node.js Basics</span></a>
<a class="toc-item" href="#buildtools"><span class="toc-num">24</span><span class="t">Build Tools</span></a>
<a class="toc-item" href="#architecture"><span class="toc-num">25</span><span class="t">Project Architecture</span></a>
<a class="toc-item" href="#capstone"><span class="toc-num">26</span><span class="t">🏆 Capstone — Expense Tracker</span></a>
<a class="toc-item" href="#projects"><span class="toc-num">27</span><span class="t">Real Project Blueprints</span></a>
<a class="toc-item" href="#diagrams"><span class="toc-num">28</span><span class="t">Diagrams</span></a>
<a class="toc-item" href="#cheatsheet"><span class="toc-num">29</span><span class="t">Cheat Sheet</span></a>
<a class="toc-item" href="#flashcards"><span class="toc-num">30</span><span class="t">Flashcards</span></a>
<a class="toc-item" href="#mnemonics"><span class="toc-num">31</span><span class="t">Mnemonics</span></a>
<a class="toc-item" href="#practiceq"><span class="toc-num">32</span><span class="t">Practice Questions</span></a>
<a class="toc-item" href="#interviewq"><span class="toc-num">33</span><span class="t">Interview Questions (Tiered)</span></a>
<a class="toc-item" href="#mistakes"><span class="toc-num">34</span><span class="t">Common Mistakes</span></a>
<a class="toc-item" href="#finalsummary"><span class="toc-num">35</span><span class="t">Final Summary</span></a>
</div>
</section>
<!-- ============ 01 INTRODUCTION ============ -->
<section id="intro" class="reveal">
<span class="eyebrow">01 · Introduction</span>
<h2 class="stitle">What is JavaScript? (Hindi + English)</h2>
<p class="sdesc"><b>Hindi:</b> JavaScript ek programming language hai jo browser me webpage ko "zinda" (interactive) banati hai. HTML deta hai structure, CSS deta hai design, JavaScript deta hai <b>behavior</b> — click, animation, data fetch, sab kuch.</p>
<p class="sdesc"><b>English:</b> JavaScript is a high-level, interpreted (actually JIT-compiled) programming language. It was created in <b>1995 by Brendan Eich</b> at Netscape in just 10 days — originally called Mocha, then LiveScript, then JavaScript (marketing name to ride Java's popularity, though the two languages are unrelated).</p>
<div class="grid g2">
<div class="card"><div class="icon-wrap">📜</div><h3>ECMAScript</h3><p style="color:var(--muted);margin-top:8px;font-size:.9rem">JavaScript language ka official "standard/rulebook" hai — TC39 committee isse maintain karti hai. Har saal ek naya version aata hai (ES2015/ES6, ES2016...ES2025). "JavaScript" implementation hai, "ECMAScript" specification hai.</p></div>
<div class="card"><div class="icon-wrap" style="background:linear-gradient(135deg,var(--mint),var(--cyan));">⚙️</div><h3>JS Engine</h3><p style="color:var(--muted);margin-top:8px;font-size:.9rem">Woh program jo JS code ko samajhkar chalata hai. Chrome/Node → <b>V8</b>. Firefox → <b>SpiderMonkey</b>. Safari → <b>JavaScriptCore</b>. Har engine apne tareeke se optimize karta hai, par ECMAScript spec follow karta hai.</p></div>
<div class="card"><div class="icon-wrap" style="background:linear-gradient(135deg,var(--orange),var(--secondary));">🔄</div><h3>Compilation vs Interpretation</h3><p style="color:var(--muted);margin-top:8px;font-size:.9rem">Purana idea: JS "interpreted" hai (line-by-line chalti hai, slow). Reality (modern engines): JS <b>JIT (Just-In-Time) compiled</b> hai — code pehle parse hota hai, phir machine code me compile hota hai runtime par, execution ke saath-saath — best of both worlds (fast startup + fast execution).</p></div>
<div class="card"><div class="icon-wrap" style="background:linear-gradient(135deg,var(--purple),var(--primary));">🌐</div><h3>Runtime Environment</h3><p style="color:var(--muted);margin-top:8px;font-size:.9rem">JS engine akela sirf language samajhta hai — DOM, fetch, setTimeout jaisi cheezein engine ka part nahi hain! Ye "runtime" (Browser ya Node.js) deta hai. Isliye same JS engine (V8) browser me aur Node me alag "runtime APIs" deta hai.</p></div>
</div>
<div class="subhead">🔹 Internal Working — V8 Engine ke andar kya hota hai</div>
<div class="ascii">Your Code
│
▼
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐
│ Parser │───▶│ Ignition │───▶│ TurboFan │
│ (AST banata │ │ (Interpreter │ │ (Optimizing JIT │
│ hai code se)│ │ — bytecode │ │ Compiler — hot │
│ │ │ chalata hai)│ │ code ko machine │
│ │ │ │ │ code me compile │
│ │ │ │ │ karta hai) │
└─────────────┘ └──────────────┘ └─────────────────┘</div>
<p style="font-size:.86rem;color:var(--muted);margin-top:10px">Engine pehle code parse karke AST (Abstract Syntax Tree) banata hai, phir Ignition interpreter usse bytecode me convert karke chalata hai. Jo function bar-bar (repeatedly) chalta hai ("hot" code), usse TurboFan highly-optimized machine code me compile kar deta hai — isliye loops jaisi cheezein time ke saath fast ho jaati hain.</p>
<div class="box dyk"><h4>💡 Did You Know?</h4>JavaScript sirf 10 din me likhi gayi thi (1995) — isiliye kuch design quirks hain (jaise <span class="mono">typeof null === 'object'</span>) jo aaj tak backward-compatibility ke liye fix nahi kiye ja sakte.</p></div>
</section>
<!-- ============ 02 SETUP ============ -->
<section id="setup" class="reveal">
<span class="eyebrow">02 · Setup</span>
<h2 class="stitle">Setting Up Your Environment</h2>
<div class="grid g2">
<div class="card"><h3>Browser Console</h3><p style="color:var(--muted);font-size:.86rem;margin-top:6px">F12 dabao → Console tab — JS turant test kar sakte ho, zero setup.</p></div>
<div class="card"><h3>VS Code</h3><p style="color:var(--muted);font-size:.86rem;margin-top:6px">Industry-standard editor. "Live Server" extension se HTML file browser me auto-refresh ke saath khulti hai.</p></div>
<div class="card"><h3>Node.js</h3><p style="color:var(--muted);font-size:.86rem;margin-top:6px">JS ko browser ke bahar (terminal me, server par) chalane deta hai — V8 engine ke upar bana hua runtime.</p></div>
<div class="card"><h3>npm / npx</h3><p style="color:var(--muted);font-size:.86rem;margin-top:6px"><span class="mono">npm</span> = Node Package Manager — libraries install karta hai. <span class="mono">npx</span> = kisi package ko bina permanently install kiye ek baar chalata hai.</p></div>
</div>
<pre><span class="cm"># Terminal commands</span>
node -v <span class="cm"># Node version check</span>
node app.js <span class="cm"># run a JS file</span>
npm init -y <span class="cm"># creates package.json (project's identity card)</span>
npm install axios <span class="cm"># installs a library into node_modules/</span></pre>
<div class="box tip"><h4>💡 package.json vs package-lock.json</h4><span class="mono">package.json</span> — tum manually likhte ho, dependencies ki "wishlist" (version ranges jaise ^1.2.0). <span class="mono">package-lock.json</span> — npm automatically banata hai, exact installed versions lock karta hai taaki "works on my machine" problem na ho.</div>
</section>
<!-- ============ 03 BASICS ============ -->
<section id="basics" class="reveal">
<span class="eyebrow">03 · Basics</span>
<h2 class="stitle">Variables & Fundamentals</h2>
<div class="subhead">🔹 let, const, var — the full story</div>
<pre><span class="kw">var</span> a = <span class="st">1</span>; <span class="cm">// old way (ES5) — function-scoped, avoid in modern code</span>
<span class="kw">let</span> b = <span class="st">2</span>; <span class="cm">// modern, block-scoped, value can change</span>
<span class="kw">const</span> c = <span class="st">3</span>; <span class="cm">// modern, block-scoped, CANNOT be reassigned</span></pre>
<div class="card"><table>
<tr><th>Feature</th><th>var</th><th>let</th><th>const</th></tr>
<tr><td>Scope</td><td>Function-scoped</td><td>Block-scoped</td><td>Block-scoped</td></tr>
<tr><td>Redeclare?</td><td>✅ Yes</td><td>❌ No</td><td>❌ No</td></tr>
<tr><td>Reassign?</td><td>✅ Yes</td><td>✅ Yes</td><td>❌ No</td></tr>
<tr><td>Hoisting</td><td>Hoisted, initialized as undefined</td><td>Hoisted but in "Temporal Dead Zone"</td><td>Same as let</td></tr>
</table></div>
<div class="box warning"><h4>⚠️ Why var is dangerous — a real bug</h4>
<pre style="margin-top:8px;font-size:.76rem">for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}
<span class="cm">// Prints: 3, 3, 3 — NOT 0, 1, 2!</span>
<span class="cm">// Why? var is function-scoped, so all 3 callbacks share the SAME i.</span>
<span class="cm">// By the time setTimeout runs, the loop has finished and i = 3.</span>
<span class="cm">// Fix: use 'let' — it creates a NEW binding per loop iteration.</span></pre></div>
<div class="box important"><h4>⭐ const ka matlab "constant value" nahi</h4><span class="mono">const</span> sirf variable ko <b>reassign</b> hone se rokta hai, object/array ke andar ke content ko nahi. <span class="mono">const arr = [1,2]; arr.push(3);</span> — ye valid hai! Sirf <span class="mono">arr = [4,5]</span> invalid hai.</div>
<div class="subhead">🔹 Naming, Keywords, Comments</div>
<pre><span class="cm">// camelCase convention — standard in JS</span>
<span class="kw">let</span> userName = <span class="st">"Raj"</span>;
<span class="kw">let</span> MAX_RETRIES = <span class="st">3</span>; <span class="cm">// UPPER_SNAKE_CASE for constants that never change</span>
<span class="cm">/* multi-line
comment */</span></pre>
<div class="subhead">🔹 Strict Mode</div>
<pre><span class="st">'use strict'</span>; <span class="cm">// top of file/function</span>
x = <span class="st">10</span>; <span class="cm">// ❌ Error in strict mode: "x is not defined" (catches accidental globals)</span></pre>
<p style="font-size:.86rem;color:var(--muted)">Strict mode silent bugs ko loud errors bana deta hai — jaise galti se global variable banana, ya read-only property ko modify karna. ES6 modules aur classes automatically strict mode me hoti hain.</p>
</section>
<!-- ============ 04 DATA TYPES ============ -->
<section id="datatypes" class="reveal">
<span class="eyebrow">04 · Data Types</span>
<h2 class="stitle">Data Types Deep Dive</h2>
<p class="sdesc">JS me 2 categories: <b>Primitive</b> (immutable, value copy hoti hai) aur <b>Non-Primitive/Reference</b> (mutable, reference copy hoti hai).</p>
<div class="grid g2">
<div class="card"><h3>Primitive Types (7)</h3><ul style="padding-left:18px;margin-top:8px;font-size:.85rem;color:var(--muted)">
<li><span class="mono">string</span> — text</li>
<li><span class="mono">number</span> — integers & floats (double-precision)</li>
<li><span class="mono">boolean</span> — true/false</li>
<li><span class="mono">undefined</span> — variable declared, value nahi diya</li>
<li><span class="mono">null</span> — intentional "koi value nahi"</li>
<li><span class="mono">bigint</span> — bade integers (Number.MAX_SAFE_INTEGER se bade)</li>
<li><span class="mono">symbol</span> — unique aur immutable identifier</li>
</ul></div>
<div class="card"><h3>Non-Primitive (Reference)</h3><ul style="padding-left:18px;margin-top:8px;font-size:.85rem;color:var(--muted)">
<li><span class="mono">object</span> — key-value pairs</li>
<li><span class="mono">array</span> — ordered list (actually a special object)</li>
<li><span class="mono">function</span> — callable object</li>
</ul></div>
</div>
<div class="subhead">🔹 The critical difference — value vs reference (memory behavior)</div>
<pre><span class="cm">// PRIMITIVE — copies the VALUE</span>
<span class="kw">let</span> a = <span class="st">10</span>;
<span class="kw">let</span> b = a; <span class="cm">// b gets its own copy: 10</span>
b = <span class="st">20</span>;
console.log(a); <span class="cm">// 10 — unaffected</span>
<span class="cm">// OBJECT — copies the REFERENCE (memory address)</span>
<span class="kw">let</span> obj1 = { val: <span class="st">10</span> };
<span class="kw">let</span> obj2 = obj1; <span class="cm">// obj2 points to the SAME object in memory</span>
obj2.val = <span class="st">20</span>;
console.log(obj1.val); <span class="cm">// 20 — changed! Both point to same memory location</span></pre>
<div class="ascii">Primitives (Stack): Objects (Heap, referenced from Stack):
a → [10] obj1 → ┐
b → [20] (own copy) ├──▶ {val: 20} (shared in Heap)
obj2 → ┘</div>
<div class="subhead">🔹 typeof — the quirky operator</div>
<pre>typeof <span class="st">42</span> <span class="cm">// "number"</span>
typeof <span class="st">"hi"</span> <span class="cm">// "string"</span>
typeof <span class="kw">true</span> <span class="cm">// "boolean"</span>
typeof <span class="kw">undefined</span> <span class="cm">// "undefined"</span>
typeof <span class="kw">null</span> <span class="cm">// "object" ❌ famous JS bug! (kept for backward-compat, never fixed)</span>
typeof {} <span class="cm">// "object"</span>
typeof [] <span class="cm">// "object" (arrays are objects — use Array.isArray() to check)</span>
typeof <span class="kw">function</span>(){} <span class="cm">// "function"</span>
typeof <span class="st">10n</span> <span class="cm">// "bigint"</span>
typeof Symbol() <span class="cm">// "symbol"</span></pre>
<div class="box interview"><h4>🎤 Interview classic — null vs undefined</h4><span class="mono">undefined</span> = JS engine ne khud diya (variable declared but not assigned, missing function argument, missing object property). <span class="mono">null</span> = developer ne <i>intentionally</i> "empty" set kiya. <span class="mono">null == undefined</span> → true (loose equality), <span class="mono">null === undefined</span> → false (different types).</div>
</section>
<!-- ============ 05 OPERATORS ============ -->
<section id="operators" class="reveal">
<span class="eyebrow">05 · Operators</span>
<h2 class="stitle">Operators & Type Coercion</h2>
<div class="grid g3">
<div class="card"><b>Arithmetic</b><p style="font-size:.8rem;color:var(--muted);margin-top:6px" class="mono">+ - * / % **</p></div>
<div class="card"><b>Assignment</b><p style="font-size:.8rem;color:var(--muted);margin-top:6px" class="mono">= += -= *= /=</p></div>
<div class="card"><b>Comparison</b><p style="font-size:.8rem;color:var(--muted);margin-top:6px" class="mono">== != === !== > < >= <=</p></div>
<div class="card"><b>Logical</b><p style="font-size:.8rem;color:var(--muted);margin-top:6px" class="mono">&& || !</p></div>
<div class="card"><b>Ternary</b><p style="font-size:.8rem;color:var(--muted);margin-top:6px" class="mono">cond ? a : b</p></div>
<div class="card"><b>Nullish/Optional</b><p style="font-size:.8rem;color:var(--muted);margin-top:6px" class="mono">?? ?.</p></div>
</div>
<div class="subhead">🔹 == vs === (the interview favorite)</div>
<pre><span class="st">5</span> == <span class="st">"5"</span> <span class="cm">// true — coerces types before comparing (loose equality)</span>
<span class="st">5</span> === <span class="st">"5"</span> <span class="cm">// false — checks type AND value (strict equality)</span>
<span class="cm">// RULE: always use === in real code. == causes confusing bugs.</span></pre>
<div class="subhead">🔹 Truthy & Falsy — the 8 falsy values (memorize these!)</div>
<div class="card"><table><tr><th>Falsy values (everything else is truthy)</th></tr>
<tr><td class="mono">false, 0, -0, 0n, "", null, undefined, NaN</td></tr>
</table></div>
<pre><span class="kw">if</span> (<span class="st">""</span>) console.log(<span class="st">"runs"</span>); <span class="cm">// doesn't run — "" is falsy</span>
<span class="kw">if</span> (<span class="st">"0"</span>) console.log(<span class="st">"runs"</span>); <span class="cm">// RUNS! "0" is a non-empty string = truthy</span></pre>
<div class="subhead">🔹 Coercion — implicit type conversion (common source of bugs)</div>
<pre><span class="st">"5"</span> + <span class="st">3</span> <span class="cm">// "53" — + with a string triggers string concatenation</span>
<span class="st">"5"</span> - <span class="st">3</span> <span class="cm">// 2 — minus forces both sides to numbers</span>
<span class="st">"5"</span> * <span class="st">"2"</span> <span class="cm">// 10 — * also forces numbers</span>
<span class="st">1</span> + <span class="kw">true</span> <span class="cm">// 2 — true becomes 1</span>
[] + [] <span class="cm">// "" — arrays become strings, "" + "" = ""</span></pre>
<div class="box warning"><h4>⚠️ Common mistake</h4>API se number "5" string me aata hai, aur developer <span class="mono">total + apiValue</span> kar deta hai — expecting math, milta hai concatenation ("105" instead of 15). Fix: <span class="mono">Number(apiValue)</span> se explicitly convert karo.</div>
<div class="box tip"><h4>💡 Optional chaining & Nullish coalescing (ES2020)</h4>
<pre style="margin-top:8px;font-size:.78rem">user?.address?.city <span class="cm">// undefined agar koi bhi step null/undefined ho, error nahi</span>
count ?? 10 <span class="cm">// 10 sirf agar count null/undefined ho (0 ya "" ko preserve karta hai, unlike ||)</span></pre></div>
</section>
<!-- ============ 06 CONTROL FLOW ============ -->
<section id="control" class="reveal">
<span class="eyebrow">06 · Control Flow</span>
<h2 class="stitle">Control Flow</h2>
<pre><span class="kw">if</span> (age >= <span class="st">18</span>) {
console.log(<span class="st">"Adult"</span>);
} <span class="kw">else if</span> (age >= <span class="st">13</span>) {
console.log(<span class="st">"Teen"</span>);
} <span class="kw">else</span> {
console.log(<span class="st">"Child"</span>);
}
<span class="kw">switch</span>(day) {
<span class="kw">case</span> <span class="st">'Mon'</span>: console.log(<span class="st">"Start"</span>); <span class="kw">break</span>;
<span class="kw">case</span> <span class="st">'Fri'</span>: console.log(<span class="st">"Almost done"</span>); <span class="kw">break</span>;
<span class="kw">default</span>: console.log(<span class="st">"Regular day"</span>);
}
<span class="kw">for</span> (<span class="kw">let</span> i=<span class="st">0</span>; i<<span class="st">5</span>; i++) { <span class="cm">/* runs 5 times */</span> }
<span class="kw">while</span>(condition) { <span class="cm">/* runs until false */</span> }
<span class="kw">do</span> { <span class="cm">/* runs at least once */</span> } <span class="kw">while</span>(condition);
<span class="kw">for</span> (<span class="kw">const</span> item <span class="kw">of</span> array) { <span class="cm">// iterates VALUES</span> }
<span class="kw">for</span> (<span class="kw">const</span> key <span class="kw">in</span> object) { <span class="cm">// iterates KEYS</span> }</pre>
<div class="box warning"><h4>⚠️ switch — mat bhoolo break!</h4>Ek case ke baad <span class="mono">break</span> na ho to "fall-through" hota hai — agla case bhi chal jaata hai chahe match na kare.</div>
<div class="box remember"><h4>🧠 for...of vs for...in</h4><span class="mono">for...of</span> arrays/strings ke <b>values</b> ke liye. <span class="mono">for...in</span> object ke <b>keys</b> ke liye — array par for...in use mat karo (unexpected inherited properties bhi mil sakti hain).</div>
</section>
<!-- ============ 07 FUNCTIONS & CLOSURES ============ -->
<section id="functions" class="reveal">
<span class="eyebrow">07 · Functions</span>
<h2 class="stitle">Functions, Scope & Closures</h2>
<div class="subhead">🔹 Function types</div>
<pre><span class="cm">// 1. Declaration — hoisted fully, can call before definition</span>
<span class="kw">function</span> <span class="fn">greet</span>(name) { <span class="kw">return</span> <span class="cm">`Hello ${name}`</span>; }
<span class="cm">// 2. Expression — NOT hoisted, stored in a variable</span>
<span class="kw">const</span> greet2 = <span class="kw">function</span>(name) { <span class="kw">return</span> <span class="cm">`Hi ${name}`</span>; };
<span class="cm">// 3. Arrow function — shorter syntax, NO OWN 'this'</span>
<span class="kw">const</span> greet3 = (name) => <span class="cm">`Hey ${name}`</span>;
<span class="cm">// 4. IIFE (Immediately Invoked Function Expression) — runs once, creates private scope</span>
(<span class="kw">function</span>() { console.log(<span class="st">"runs immediately"</span>); })();</pre>
<div class="subhead">🔹 Why arrow functions and normal functions are NOT interchangeable</div>
<pre><span class="kw">const</span> obj = {
name: <span class="st">'Raj'</span>,
greetNormal: <span class="kw">function</span>() { console.log(this.name); }, <span class="cm">// 'this' = obj → "Raj"</span>
greetArrow: () => { console.log(this.name); } <span class="cm">// 'this' = outer scope → undefined!</span>
};
obj.greetNormal(); <span class="cm">// "Raj"</span>
obj.greetArrow(); <span class="cm">// undefined — arrow functions don't have their own 'this'</span></pre>
<div class="subhead">🔹 Closures — the most important JS concept</div>
<p style="font-size:.9rem;color:var(--muted);margin-bottom:8px"><b>Why it exists:</b> Normally jab function return ho jaata hai, uske andar ki variables "gayab" ho jaani chahiye (garbage collected). Par closures inhe "yaad" rakhte hain — agar koi inner function unhe use kar raha ho.</p>
<pre><span class="kw">function</span> <span class="fn">makeCounter</span>() {
<span class="kw">let</span> count = <span class="st">0</span>; <span class="cm">// this variable is "enclosed"</span>
<span class="kw">return function</span>() { <span class="cm">// inner function "remembers" count forever</span>
count++;
<span class="kw">return</span> count;
};
}
<span class="kw">const</span> counter = <span class="fn">makeCounter</span>();
counter(); <span class="cm">// 1</span>
counter(); <span class="cm">// 2 — count persisted between calls!</span>
counter(); <span class="cm">// 3</span></pre>
<p style="font-size:.86rem;color:var(--muted)"><b>How it works internally:</b> Har function call ek naya "execution context" banata hai jisme ek "lexical environment" hota hai. Jab inner function bahar return hoti hai, JS engine outer variables ko garbage-collect nahi karta agar inner function abhi bhi unhe reference kar rahi hai — ye variables "closure" ke andar zinda rehte hain.</p>
<div class="box important"><h4>⭐ Real project use — Closures</h4>Private variables banana (module pattern), event handler ke andar current state "remember" karna, <span class="mono">useState</span>/<span class="mono">useEffect</span> jaise React hooks internally closures hi use karte hain, debounce/throttle functions.</div>
<div class="subhead">🔹 Lexical Scope & Scope Chain</div>
<pre><span class="kw">let</span> globalVar = <span class="st">"global"</span>;
<span class="kw">function</span> <span class="fn">outer</span>() {
<span class="kw">let</span> outerVar = <span class="st">"outer"</span>;
<span class="kw">function</span> <span class="fn">inner</span>() {
<span class="kw">let</span> innerVar = <span class="st">"inner"</span>;
console.log(innerVar, outerVar, globalVar); <span class="cm">// all accessible!</span>
}
<span class="fn">inner</span>();
}
<span class="cm">// "Lexical" = scope decided by WHERE code is WRITTEN, not where it's called from.</span>
<span class="cm">// inner() can see outer's variables because it's physically nested inside it.</span></pre>
<div class="subhead">🔹 Rest, Spread, Default Parameters</div>
<pre><span class="kw">function</span> <span class="fn">sum</span>(...numbers) { <span class="cm">// rest — collects args into an array</span>
<span class="kw">return</span> numbers.reduce((a,b) => a+b, <span class="st">0</span>);
}
<span class="fn">sum</span>(<span class="st">1</span>,<span class="st">2</span>,<span class="st">3</span>); <span class="cm">// 6</span>
<span class="kw">const</span> arr1 = [<span class="st">1</span>,<span class="st">2</span>];
<span class="kw">const</span> arr2 = [...arr1, <span class="st">3</span>,<span class="st">4</span>]; <span class="cm">// spread — expands array into elements: [1,2,3,4]</span>
<span class="kw">function</span> <span class="fn">greet</span>(name = <span class="st">"Guest"</span>) { <span class="cm">// default parameter</span>
<span class="kw">return</span> <span class="cm">`Hi ${name}`</span>;
}
<span class="fn">greet</span>(); <span class="cm">// "Hi Guest"</span></pre>
<div class="subhead">🔹 Higher-Order Functions & Callbacks</div>
<pre><span class="cm">// A function that takes/returns another function = Higher-Order Function</span>
<span class="kw">function</span> <span class="fn">withLogging</span>(fn) {
<span class="kw">return function</span>(...args) {
console.log(<span class="st">'Calling with:'</span>, args);
<span class="kw">return</span> fn(...args);
};
}
<span class="kw">const</span> loggedAdd = <span class="fn">withLogging</span>((a,b) => a+b);
<span class="fn">loggedAdd</span>(<span class="st">2</span>,<span class="st">3</span>); <span class="cm">// logs "Calling with: [2,3]", returns 5</span></pre>
<div class="subhead">🔹 Recursion</div>
<pre><span class="kw">function</span> <span class="fn">factorial</span>(n) {
<span class="kw">if</span> (n <= <span class="st">1</span>) <span class="kw">return</span> <span class="st">1</span>; <span class="cm">// BASE CASE — without this, infinite recursion → stack overflow!</span>
<span class="kw">return</span> n * <span class="fn">factorial</span>(n - <span class="st">1</span>);
}
<span class="fn">factorial</span>(<span class="st">5</span>); <span class="cm">// 120</span></pre>
<div class="box warning"><h4>⚠️ Common mistake — missing base case</h4>Har recursive function ko ek "stopping condition" chahiye, warna Call Stack overflow ho jaata hai ("Maximum call stack size exceeded").</div>
<div class="box shortcut"><h4>⏩ Pro Tips</h4>Chrome DevTools me function ke andar <span class="mono">debugger;</span> likho — execution wahi pause ho jaayegi jab DevTools khula ho. Arrow functions use karo callbacks ke liye jab tumhe 'this' binding nahi chahiye; normal functions use karo object methods ke liye jab chahiye.</div>
</section>
<!-- ============ 08 OBJECTS ============ -->
<section id="objects" class="reveal">
<span class="eyebrow">08 · Objects</span>
<h2 class="stitle">Objects, this, Prototypes</h2>
<div class="subhead">🔹 Object basics</div>
<pre><span class="kw">const</span> person = {
name: <span class="st">'Raj'</span>,
age: <span class="st">20</span>,
greet() { <span class="kw">return</span> <span class="cm">`Hi, I'm ${this.name}`</span>; } <span class="cm">// method shorthand</span>
};
person.name; <span class="cm">// dot notation</span>
person[<span class="st">'name'</span>]; <span class="cm">// bracket notation — needed for dynamic keys</span>
<span class="kw">const</span> { name, age } = person; <span class="cm">// destructuring</span></pre>
<div class="subhead">🔹 'this' — depends on HOW a function is called, not where it's defined</div>
<div class="card"><table>
<tr><th>Call pattern</th><th>What 'this' is</th></tr>
<tr><td class="mono">obj.method()</td><td>obj (the object before the dot)</td></tr>
<tr><td class="mono">standalone function()</td><td>undefined (strict mode) / global object</td></tr>
<tr><td class="mono">arrow function</td><td>whatever 'this' was in the ENCLOSING scope</td></tr>
<tr><td class="mono">new Constructor()</td><td>the newly created object</td></tr>
<tr><td class="mono">fn.call(obj)</td><td>explicitly set to obj</td></tr>
</table></div>
<div class="subhead">🔹 call, apply, bind</div>
<pre><span class="kw">function</span> <span class="fn">introduce</span>(greeting) { <span class="kw">return</span> <span class="cm">`${greeting}, I'm ${this.name}`</span>; }
<span class="kw">const</span> user = { name: <span class="st">'Raj'</span> };
<span class="fn">introduce</span>.call(user, <span class="st">'Hi'</span>); <span class="cm">// runs NOW, args passed individually: "Hi, I'm Raj"</span>
<span class="fn">introduce</span>.apply(user, [<span class="st">'Hi'</span>]); <span class="cm">// runs NOW, args passed as array</span>
<span class="kw">const</span> bound = <span class="fn">introduce</span>.bind(user); <span class="cm">// returns a NEW function, doesn't run yet</span>
bound(<span class="st">'Hey'</span>); <span class="cm">// "Hey, I'm Raj" — 'this' permanently locked to user</span></pre>
<div class="box tip"><h4>💡 Real project use</h4><span class="mono">bind</span> React class components me event handlers ke liye common tha (<span class="mono">this.handleClick = this.handleClick.bind(this)</span>) — modern code me arrow function class fields se avoid karte hain.</div>
<div class="subhead">🔹 Prototype & Prototype Chain</div>
<p style="font-size:.9rem;color:var(--muted);margin-bottom:8px"><b>Why it exists:</b> JS me classical "class" inheritance (jaise Java) nahi hai — JS <b>prototype-based</b> hai. Har object ke paas ek hidden link (<span class="mono">[[Prototype]]</span>) hota hai kisi doosre object ki taraf, jahan se woh properties/methods "udhaar" (inherit) leta hai.</p>
<pre><span class="kw">const</span> animal = { eats: <span class="kw">true</span> };
<span class="kw">const</span> rabbit = Object.create(animal); <span class="cm">// rabbit's prototype = animal</span>
rabbit.jumps = <span class="kw">true</span>;
console.log(rabbit.eats); <span class="cm">// true — found on prototype chain, not on rabbit itself!</span>
console.log(rabbit.jumps); <span class="cm">// true — own property</span></pre>
<div class="ascii">rabbit {jumps: true}
│ [[Prototype]]
▼
animal {eats: true}
│ [[Prototype]]
▼
Object.prototype {toString, hasOwnProperty, ...}
│
▼
null (end of chain)</div>
<p style="font-size:.86rem;color:var(--muted)">Jab tum <span class="mono">rabbit.eats</span> access karte ho, engine pehle rabbit khud check karta hai, na mile to prototype chain "upar" search karta hai jab tak mil na jaaye ya null tak pahunch jaaye.</p>
<div class="subhead">🔹 Property Descriptors</div>
<pre>Object.defineProperty(person, <span class="st">'age'</span>, {
value: <span class="st">20</span>,
writable: <span class="kw">false</span>, <span class="cm">// can't be reassigned</span>
enumerable: <span class="kw">true</span>, <span class="cm">// shows up in for...in / Object.keys</span>
configurable: <span class="kw">false</span> <span class="cm">// can't be deleted or reconfigured</span>
});</pre>
<div class="box interview"><h4>🎤 Interview — Object.freeze() vs const</h4><span class="mono">const</span> variable ko reassign hone se rokta hai. <span class="mono">Object.freeze(obj)</span> object ke andar ki properties ko change hone se rokta hai (shallow — nested objects freeze nahi hote).</div>
</section>
<!-- ============ 09 ARRAYS ============ -->
<section id="arrays" class="reveal">
<span class="eyebrow">09 · Arrays</span>
<h2 class="stitle">Arrays — Every Method Explained</h2>
<p class="sdesc">Array JS me ek special object hai — numeric keys ke saath. Methods ko 2 categories me samjho: <b>mutating</b> (original array badalte hain) aur <b>non-mutating</b> (naya array return karte hain).</p>
<div class="subhead">🔹 Mutating methods (original array change hota hai)</div>
<div class="card"><table>
<tr><th>Method</th><th>What it does</th><th>Time Complexity</th></tr>
<tr><td class="mono">push(x)</td><td>End me add karta hai</td><td>O(1)</td></tr>
<tr><td class="mono">pop()</td><td>End se remove karta hai</td><td>O(1)</td></tr>
<tr><td class="mono">unshift(x)</td><td>Start me add karta hai</td><td>O(n) — sab elements shift hote hain</td></tr>
<tr><td class="mono">shift()</td><td>Start se remove karta hai</td><td>O(n)</td></tr>
<tr><td class="mono">splice(i, count)</td><td>Beech se add/remove</td><td>O(n)</td></tr>
<tr><td class="mono">sort(), reverse()</td><td>In-place sort/reverse</td><td>O(n log n) / O(n)</td></tr>
</table></div>
<div class="subhead">🔹 Non-mutating methods (naya array/value return karte hain — preferred!)</div>
<pre><span class="kw">const</span> nums = [<span class="st">1</span>,<span class="st">2</span>,<span class="st">3</span>,<span class="st">4</span>,<span class="st">5</span>];
nums.map(n => n * <span class="st">2</span>); <span class="cm">// [2,4,6,8,10] — transforms each element</span>
nums.filter(n => n % <span class="st">2</span> === <span class="st">0</span>); <span class="cm">// [2,4] — keeps elements matching condition</span>
nums.reduce((sum,n) => sum+n, <span class="st">0</span>); <span class="cm">// 15 — combines all into ONE value</span>
nums.find(n => n > <span class="st">3</span>); <span class="cm">// 4 — first matching element</span>
nums.some(n => n > <span class="st">4</span>); <span class="cm">// true — is ANY element matching?</span>
nums.every(n => n > <span class="st">0</span>); <span class="cm">// true — are ALL elements matching?</span>
nums.slice(<span class="st">1</span>,<span class="st">3</span>); <span class="cm">// [2,3] — extract portion, original unchanged</span>
nums.includes(<span class="st">3</span>); <span class="cm">// true</span>
nums.join(<span class="st">'-'</span>); <span class="cm">// "1-2-3-4-5"</span></pre>
<div class="box important"><h4>⭐ splice vs slice — the classic confusion</h4><span class="mono">slice(start, end)</span> — original array ko chhuti nahi, naya array return karta hai (non-mutating). <span class="mono">splice(start, deleteCount, ...items)</span> — original array ko directly modify karta hai (mutating), removed elements return karta hai.</div>
<div class="subhead">🔹 reduce — the most powerful (and confusing) method</div>
<pre><span class="cm">// reduce can build ANYTHING — sum, max, group, flatten, even map/filter!</span>
<span class="kw">const</span> cart = [{price:<span class="st">100</span>},{price:<span class="st">200</span>},{price:<span class="st">50</span>}];
<span class="kw">const</span> total = cart.reduce((acc, item) => acc + item.price, <span class="st">0</span>); <span class="cm">// 350</span>
<span class="cm">// grouping example — very common in real projects</span>
<span class="kw">const</span> people = [{name:<span class="st">'A'</span>,dept:<span class="st">'HR'</span>},{name:<span class="st">'B'</span>,dept:<span class="st">'IT'</span>},{name:<span class="st">'C'</span>,dept:<span class="st">'HR'</span>}];
<span class="kw">const</span> grouped = people.reduce((acc, p) => {
(acc[p.dept] ??= []).push(p);
<span class="kw">return</span> acc;
}, {});
<span class="cm">// { HR: [A,C], IT: [B] }</span></pre>
<div class="box shortcut"><h4>⏩ Pro Tip</h4>Real projects me chain karo: <span class="mono">data.filter(...).map(...).sort(...)</span> — readable pipeline banti hai. Bade arrays (10,000+) par chaining se performance concern ho to ek hi loop me combine karo.</div>
<div class="box warning"><h4>⚠️ Common mistake</h4><span class="mono">array.sort()</span> default me elements ko STRING me convert karke sort karta hai — <span class="mono">[10, 2, 1].sort()</span> deta hai <span class="mono">[1, 10, 2]</span>, not [1,2,10]! Numbers ke liye <span class="mono">sort((a,b) => a-b)</span> use karo.</div>
</section>
<!-- ============ 10 STRINGS/NUMBERS/DATES/MATH/JSON ============ -->
<section id="strings" class="reveal">
<span class="eyebrow">10 · Strings, Numbers, Dates</span>
<h2 class="stitle">Strings, Numbers, Dates, Math, JSON</h2>
<div class="subhead">🔹 Strings</div>
<pre><span class="kw">const</span> name = <span class="st">"Raj Gahoi"</span>;
name.length; <span class="cm">// 9</span>
name.toUpperCase(); <span class="cm">// "RAJ GAHOI"</span>
name.slice(<span class="st">0</span>,<span class="st">3</span>); <span class="cm">// "Raj"</span>
name.includes(<span class="st">"Gahoi"</span>); <span class="cm">// true</span>
name.split(<span class="st">' '</span>); <span class="cm">// ["Raj","Gahoi"]</span>
name.trim(); <span class="cm">// removes whitespace from both ends</span>
name.replace(<span class="st">"Raj"</span>, <span class="st">"Mr."</span>); <span class="cm">// "Mr. Gahoi"</span>
<span class="cm">// Template literals (ES6) — much cleaner than concatenation</span>
<span class="kw">const</span> greeting = <span class="cm">`Hello, ${name}! You are ${<span class="st">20</span>} years old.`</span>;</pre>
<div class="subhead">🔹 Numbers & Math</div>
<pre>Number(<span class="st">"42"</span>); <span class="cm">// 42 — explicit conversion</span>
parseInt(<span class="st">"42px"</span>); <span class="cm">// 42 — parses until non-digit</span>
(<span class="st">3.14159</span>).toFixed(<span class="st">2</span>); <span class="cm">// "3.14"</span>
Number.isInteger(<span class="st">5</span>); <span class="cm">// true</span>
Math.max(<span class="st">1</span>,<span class="st">5</span>,<span class="st">3</span>); <span class="cm">// 5</span>
Math.floor(<span class="st">4.7</span>); <span class="cm">// 4</span>
Math.round(<span class="st">4.5</span>); <span class="cm">// 5</span>
Math.random(); <span class="cm">// 0 to 1 (exclusive)</span>
Math.floor(Math.random() * <span class="st">10</span>); <span class="cm">// random integer 0-9</span></pre>
<div class="box warning"><h4>⚠️ Floating point precision (famous JS quirk)</h4><span class="mono">0.1 + 0.2 === 0.3</span> → <b>false</b>! Result is 0.30000000000000004 due to how floating-point binary math works. Fix: <span class="mono">Math.abs(a-b) < Number.EPSILON</span> ya <span class="mono">toFixed()</span> se compare karo.</div>
<div class="subhead">🔹 Dates</div>
<pre><span class="kw">const</span> now = <span class="kw">new</span> Date();
now.getFullYear(); <span class="cm">// 2026</span>
now.getMonth(); <span class="cm">// 0-11 (Jan=0!) — common off-by-one bug</span>
now.getDate(); <span class="cm">// day of month</span>
now.toISOString(); <span class="cm">// "2026-07-27T10:30:00.000Z" — standard format for APIs</span></pre>
<div class="box tip"><h4>💡 Pro tip</h4>Native Date API clunky hai — real projects me <span class="mono">date-fns</span> ya <span class="mono">dayjs</span> library use karo formatting/timezone ke liye.</div>
<div class="subhead">🔹 JSON</div>
<pre><span class="kw">const</span> obj = { name: <span class="st">"Raj"</span>, age: <span class="st">20</span> };
<span class="kw">const</span> str = JSON.stringify(obj); <span class="cm">// '{"name":"Raj","age":20}' — object → string</span>
<span class="kw">const</span> back = JSON.parse(str); <span class="cm">// {name:"Raj",age:20} — string → object</span></pre>
<p style="font-size:.86rem;color:var(--muted)">API se data JSON string me aata hai — <span class="mono">fetch(...).then(r => r.json())</span> internally <span class="mono">JSON.parse</span> hi kar raha hota hai. localStorage me sirf strings store ho sakti hain, isliye objects save karne se pehle <span class="mono">stringify</span> karna padta hai.</p>
</section>
<!-- ============ 11 ERROR HANDLING ============ -->
<section id="errors" class="reveal">
<span class="eyebrow">11 · Error Handling</span>
<h2 class="stitle">Error Handling</h2>
<pre><span class="kw">try</span> {
<span class="kw">const</span> data = JSON.parse(invalidJson); <span class="cm">// might throw</span>
} <span class="kw">catch</span> (error) {
console.error(<span class="st">'Failed:'</span>, error.message);
} <span class="kw">finally</span> {
console.log(<span class="st">'This always runs'</span>); <span class="cm">// cleanup — runs whether error or not</span>
}</pre>
<div class="subhead">🔹 Custom Errors — real project pattern</div>
<pre><span class="kw">class</span> ValidationError <span class="kw">extends</span> Error {
<span class="fn">constructor</span>(message, field) {
<span class="kw">super</span>(message);
this.name = <span class="st">'ValidationError'</span>;
this.field = field;
}
}
<span class="kw">function</span> <span class="fn">validateAge</span>(age) {
<span class="kw">if</span> (age < <span class="st">0</span>) <span class="kw">throw new</span> ValidationError(<span class="st">'Age cannot be negative'</span>, <span class="st">'age'</span>);
<span class="kw">return</span> age;
}
<span class="kw">try</span> {
<span class="fn">validateAge</span>(-<span class="st">5</span>);
} <span class="kw">catch</span> (e) {
<span class="kw">if</span> (e <span class="kw">instanceof</span> ValidationError) {
console.log(<span class="cm">`Invalid field: ${e.field}`</span>);
}
}</pre>
<div class="box important"><h4>⭐ Why custom errors matter in real projects</h4>Alag-alag error types (ValidationError, NetworkError, AuthError) se code specific handling kar sakta hai — jaise validation error par form field highlight karo, auth error par login page bhejo.</div>
<div class="box warning"><h4>⚠️ Common mistake</h4>Async code me try/catch bhoolna — <span class="mono">await fetch()</span> fail ho sakta hai (network down), bina try/catch ke poori app crash ho sakti hai (unhandled promise rejection).</div>
</section>
<!-- ============ 12 MODULES ============ -->
<section id="modules" class="reveal">
<span class="eyebrow">12 · Modules</span>
<h2 class="stitle">Modules</h2>
<p class="sdesc"><b>Why modules exist:</b> Poora code ek hi file me likhna unmanageable ho jaata hai, aur global scope pollute hota hai (naming clashes). Modules code ko alag files me tod kar explicitly export/import karne dete hain.</p>
<div class="subhead">🔹 CommonJS (Node.js traditional)</div>
<pre><span class="cm">// math.js</span>
<span class="kw">function</span> <span class="fn">add</span>(a,b) { <span class="kw">return</span> a+b; }
module.exports = { add };
<span class="cm">// app.js</span>
<span class="kw">const</span> { add } = require(<span class="st">'./math'</span>);</pre>
<div class="subhead">🔹 ES Modules (modern standard, browser + Node)</div>
<pre><span class="cm">// math.js</span>
<span class="kw">export function</span> <span class="fn">add</span>(a,b) { <span class="kw">return</span> a+b; }
<span class="kw">export default function</span> <span class="fn">multiply</span>(a,b) { <span class="kw">return</span> a*b; }
<span class="cm">// app.js</span>
<span class="kw">import</span> multiply, { add } <span class="kw">from</span> <span class="st">'./math.js'</span>;</pre>
<div class="subhead">🔹 Dynamic Import & Tree Shaking</div>
<pre><span class="cm">// Load a module only when needed (code splitting)</span>
<span class="kw">const</span> module = <span class="kw">await</span> import(<span class="st">'./heavyFeature.js'</span>);</pre>
<div class="box tip"><h4>💡 Tree Shaking</h4>Modern bundlers (Vite/Webpack) unused exports ko automatically final bundle se hata dete hain agar tum ES Modules (named exports) use karo — isliye bundle size chhota rehta hai. CommonJS ke saath tree shaking properly kaam nahi karta.</div>
</section>
<!-- ============ 13 DOM & EVENTS ============ -->
<section id="dom" class="reveal">
<span class="eyebrow">13 · DOM & Events</span>
<h2 class="stitle">DOM, Events & Browser APIs</h2>
<p class="sdesc">DOM (Document Object Model) HTML ka in-memory tree representation hai — JS isi tree ko padh/badal sakta hai, jisse page update hota hai.</p>
<div class="subhead">🔹 Selecting & Modifying Elements</div>
<pre><span class="kw">const</span> el = document.querySelector(<span class="st">'.card'</span>); <span class="cm">// first match</span>
<span class="kw">const</span> all = document.querySelectorAll(<span class="st">'.card'</span>); <span class="cm">// NodeList of all matches</span>
el.textContent = <span class="st">'New text'</span>;
el.classList.add(<span class="st">'active'</span>);
el.style.color = <span class="st">'red'</span>;
el.setAttribute(<span class="st">'data-id'</span>, <span class="st">'5'</span>);</pre>
<div class="subhead">🔹 Events</div>
<pre><span class="kw">const</span> btn = document.querySelector(<span class="st">'#save'</span>);
btn.addEventListener(<span class="st">'click'</span>, (e) => {
e.preventDefault(); <span class="cm">// stops default behaviour (form submit, link navigate)</span>
console.log(<span class="st">'clicked'</span>, e.target);
});</pre>
<div class="subhead">🔹 Event Bubbling & Delegation (important real-project pattern)</div>
<pre><span class="cm">// Instead of adding a listener to EVERY button (expensive if 1000s of items):</span>
document.querySelector(<span class="st">'#list'</span>).addEventListener(<span class="st">'click'</span>, (e) => {
<span class="kw">if</span> (e.target.matches(<span class="st">'.delete-btn'</span>)) {
<span class="fn">deleteItem</span>(e.target.dataset.id);
}
});
<span class="cm">// Events "bubble up" from child to parent — so ONE listener on the parent</span>
<span class="cm">// catches clicks on ALL children, even ones added LATER dynamically.</span></pre>
<div class="box important"><h4>⭐ Why event delegation matters</h4>Dynamic lists (chat messages, todo items) me naye elements add hote rehte hain — unpar seedha listener lagane se woh listener nahi milega. Delegation se parent ek hi listener rakhta hai jo hamesha kaam karta hai, chahe child kabhi bhi add ho.</div>
<div class="subhead">🔹 Browser APIs — fetch, DOM ke bahar ki cheezein</div>
<pre><span class="kw">const</span> res = <span class="kw">await</span> fetch(<span class="st">'https://api.example.com/users'</span>);
<span class="kw">const</span> users = <span class="kw">await</span> res.json();</pre>
</section>
<!-- ============ 14 STORAGE ============ -->
<section id="storage" class="reveal">
<span class="eyebrow">14 · Storage</span>
<h2 class="stitle">Browser Storage</h2>
<div class="card"><table>
<tr><th>Storage</th><th>Capacity</th><th>Persists?</th><th>Sent to server?</th></tr>
<tr><td>localStorage</td><td>~5-10MB</td><td>Forever (until cleared)</td><td>No</td></tr>
<tr><td>sessionStorage</td><td>~5-10MB</td><td>Tab close tak</td><td>No</td></tr>
<tr><td>Cookies</td><td>~4KB</td><td>Configurable expiry</td><td>Yes, every request</td></tr>
<tr><td>IndexedDB</td><td>Much larger (100s of MB)</td><td>Forever</td><td>No</td></tr>
</table></div>
<pre>localStorage.setItem(<span class="st">'theme'</span>, <span class="st">'dark'</span>);
localStorage.getItem(<span class="st">'theme'</span>); <span class="cm">// "dark"</span>
localStorage.removeItem(<span class="st">'theme'</span>);
<span class="cm">// Objects must be stringified first:</span>
localStorage.setItem(<span class="st">'user'</span>, JSON.stringify({name:<span class="st">'Raj'</span>}));
<span class="kw">const</span> user = JSON.parse(localStorage.getItem(<span class="st">'user'</span>));</pre>
<div class="box warning"><h4>⚠️ Never store secrets in localStorage</h4>JS-accessible storage XSS attacks se readable hai — tokens/passwords yahan store karna security risk hai. Sensitive tokens ke liye httpOnly cookies better hain.</div>
</section>
<!-- ============ 15 ASYNC & EVENT LOOP ============ -->
<section id="async" class="reveal">
<span class="eyebrow">15 · Async JavaScript</span>
<h2 class="stitle">Async JS & The Event Loop</h2>
<p class="sdesc"><b>Why this exists:</b> JavaScript <b>single-threaded</b> hai — ek waqt me sirf ek cheez chal sakti hai. Agar API call ka response 3 second lage aur JS "wait" kare, poori website 3 second ke liye freeze ho jaayegi! Async JS isi problem ko solve karta hai — "kaam background me chalne do, jab ready ho tab bata dena."</p>
<div class="subhead">🔹 Evolution: Callback → Promise → async/await</div>
<pre><span class="cm">// 1. CALLBACKS (old way) — leads to "Callback Hell" when nested</span>
<span class="fn">getUser</span>(id, (user) => {
<span class="fn">getPosts</span>(user.id, (posts) => {
<span class="fn">getComments</span>(posts[<span class="st">0</span>].id, (comments) => {
console.log(comments); <span class="cm">// deeply nested — hard to read/maintain</span>
});
});
});
<span class="cm">// 2. PROMISES — flattens the nesting with .then() chaining</span>
<span class="fn">getUser</span>(id)
.then(user => <span class="fn">getPosts</span>(user.id))
.then(posts => <span class="fn">getComments</span>(posts[<span class="st">0</span>].id))
.then(comments => console.log(comments))
.catch(err => console.error(err));
<span class="cm">// 3. ASYNC/AWAIT (modern) — looks synchronous, easiest to read</span>
<span class="kw">async function</span> <span class="fn">loadData</span>() {
<span class="kw">try</span> {
<span class="kw">const</span> user = <span class="kw">await</span> <span class="fn">getUser</span>(id);
<span class="kw">const</span> posts = <span class="kw">await</span> <span class="fn">getPosts</span>(user.id);
<span class="kw">const</span> comments = <span class="kw">await</span> <span class="fn">getComments</span>(posts[<span class="st">0</span>].id);
console.log(comments);
} <span class="kw">catch</span> (err) {
console.error(err);
}
}</pre>
<p style="font-size:.86rem;color:var(--muted)"><b>Internally:</b> async/await Promises ka hi "syntactic sugar" hai — engine ke andar exactly wahi promise chain ban rahi hoti hai, bas likhna aur padhna easier ho gaya hai.</p>
<div class="subhead">🔹 Promise states & creation</div>
<pre><span class="kw">const</span> promise = <span class="kw">new</span> Promise((resolve, reject) => {
<span class="kw">const</span> success = <span class="kw">true</span>;
<span class="kw">if</span> (success) resolve(<span class="st">'Data loaded'</span>);
<span class="kw">else</span> reject(<span class="st">'Failed'</span>);
});
<span class="cm">// A promise is always in ONE of 3 states: pending → fulfilled OR rejected</span></pre>
<div class="subhead">🔹 Promise.all, allSettled, race</div>
<pre><span class="kw">const</span> [users, posts] = <span class="kw">await</span> Promise.all([<span class="fn">getUsers</span>(), <span class="fn">getPosts</span>()]);
<span class="cm">// runs both in PARALLEL, waits for both. If ANY fails, whole thing rejects.</span>
<span class="kw">const</span> results = <span class="kw">await</span> Promise.allSettled([p1, p2, p3]);
<span class="cm">// waits for ALL, regardless of success/failure — each result has {status, value/reason}</span>
<span class="kw">const</span> fastest = <span class="kw">await</span> Promise.race([p1, p2]);
<span class="cm">// resolves/rejects as soon as the FIRST one settles</span></pre>
<div class="subhead">🔹 THE EVENT LOOP — how async actually works internally</div>
<div class="ascii">┌─────────────┐
│ Call Stack │ ◀── your synchronous code runs here, one frame at a time
└─────────────┘
│ (when stack is EMPTY, event loop checks queues)
▼
┌───────────────────────┐ ┌──────────────────────────┐
│ Microtask Queue │ │ Macrotask (Callback) │
│ (Promises, .then, │ ───▶ │ Queue (setTimeout, │
│ queueMicrotask) │ ALL │ setInterval, DOM events)│
│ runs COMPLETELY first │ done │ runs ONE task, then │
│ │ │ checks microtasks again │
└───────────────────────┘ └──────────────────────────┘</div>
<pre><span class="fn">console</span>.log(<span class="st">'1'</span>); <span class="cm">// synchronous — runs immediately</span>
setTimeout(() => console.log(<span class="st">'2'</span>), <span class="st">0</span>); <span class="cm">// macrotask — queued for LATER</span>
Promise.resolve().then(() => console.log(<span class="st">'3'</span>)); <span class="cm">// microtask — queued, but HIGHER priority than macrotask</span>
<span class="fn">console</span>.log(<span class="st">'4'</span>); <span class="cm">// synchronous</span>
<span class="cm">// Output: 1, 4, 3, 2</span>
<span class="cm">// Why: sync code (1,4) runs first. Then ALL microtasks (3). Then macrotasks (2).</span></pre>
<div class="box important"><h4>⭐ Interview gold — why this matters</h4>Ye samajhna React re-renders, debouncing, aur "why did my setTimeout not run exactly at 0ms" jaise bugs debug karne ke liye critical hai. Microtasks (Promises) hamesha macrotasks (setTimeout) se pehle chalte hain, chahe setTimeout ka delay 0 hi kyun na ho.</div>
<div class="subhead">🔹 Fetch & AbortController</div>
<pre><span class="kw">const</span> controller = <span class="kw">new</span> AbortController();
<span class="kw">const</span> timeoutId = setTimeout(() => controller.abort(), <span class="st">5000</span>); <span class="cm">// cancel after 5s</span>
<span class="kw">try</span> {
<span class="kw">const</span> res = <span class="kw">await</span> fetch(url, { signal: controller.signal });
clearTimeout(timeoutId);
} <span class="kw">catch</span> (e) {
<span class="kw">if</span> (e.name === <span class="st">'AbortError'</span>) console.log(<span class="st">'Request timed out'</span>);
}</pre>
<div class="box shortcut"><h4>⏩ Pro Tip</h4>Search/autocomplete inputs me AbortController use karo purani, ab-irrelevant API requests cancel karne ke liye jab user tez type kare — warna race condition ho sakti hai (purani response naye se baad me aa jaaye).</div>
</section>
<!-- ============ 16 OOP ============ -->
<section id="oop" class="reveal">
<span class="eyebrow">16 · OOP</span>
<h2 class="stitle">Object-Oriented JavaScript</h2>
<pre><span class="kw">class</span> Animal {
<span class="fn">constructor</span>(name) {
this.name = name; <span class="cm">// instance property</span>
}
<span class="fn">speak</span>() { <span class="cm">// method — shared via prototype, not copied per instance</span>
<span class="kw">return</span> <span class="cm">`${this.name} makes a sound`</span>;
}
}
<span class="kw">class</span> Dog <span class="kw">extends</span> Animal { <span class="cm">// inheritance</span>
<span class="fn">speak</span>() { <span class="cm">// method OVERRIDING (polymorphism)</span>
<span class="kw">return</span> <span class="cm">`${this.name} barks`</span>;
}
}
<span class="kw">const</span> d = <span class="kw">new</span> Dog(<span class="st">'Tommy'</span>);
d.speak(); <span class="cm">// "Tommy barks"</span></pre>
<div class="grid g2">
<div class="box definition"><h4>Encapsulation</h4>Data aur uspar operate karne wale methods ko ek unit (class) me bundle karna. Private fields: <span class="mono">#balance</span> (ES2022) — sirf class ke andar accessible.</div>
<div class="box definition"><h4>Inheritance</h4><span class="mono">extends</span> se ek class doosri ki properties/methods "inherit" karti hai — code reuse.</div>
<div class="box definition"><h4>Polymorphism</h4>Same method name, different behavior per class (jaise upar <span class="mono">speak()</span> Dog me override hua).</div>
<div class="box definition"><h4>Abstraction</h4>Complex implementation ko chhupa kar simple interface expose karna (jaise <span class="mono">fetch()</span> — internal networking complexity hidden hai).</div>
</div>
<pre><span class="kw">class</span> BankAccount {
<span class="kw">#balance</span> = <span class="st">0</span>; <span class="cm">// private field (ES2022) — truly inaccessible outside class</span>
<span class="fn">deposit</span>(amount) { this.<span class="kw">#balance</span> += amount; }
<span class="fn">getBalance</span>() { <span class="kw">return</span> this.<span class="kw">#balance</span>; }
}
<span class="kw">const</span> acc = <span class="kw">new</span> BankAccount();
acc.<span class="kw">#balance</span>; <span class="cm">// ❌ SyntaxError — can't access from outside!</span></pre>
<div class="box tip"><h4>💡 Real project use</h4>Classes React class components me (legacy), Node.js backend me models/services banane ke liye, aur kisi bhi domain modeling (User, Product, Order classes) ke liye use hoti hain.</div>
</section>
<!-- ============ 17 FUNCTIONAL PROGRAMMING ============ -->
<section id="fp" class="reveal">
<span class="eyebrow">17 · Functional Programming</span>
<h2 class="stitle">Functional Programming</h2>
<div class="grid g2">
<div class="box definition"><h4>Pure Functions</h4>Same input → hamesha same output, koi side effects nahi (outside variables ko touch nahi karti). Testing aur debugging easy ho jaata hai.
<pre style="font-size:.74rem;margin-top:6px">// Pure
function add(a,b) { return a+b; }
// Impure — depends on external state
let tax = 0.1;
function addTax(price) { return price + price*tax; }</pre></div>
<div class="box definition"><h4>Immutability</h4>Data ko directly modify na karke, changes ke saath naya data banana. React state updates isi principle par based hain.</div>
<div class="box definition"><h4>Function Composition</h4>Chhote functions ko combine karke complex logic banana.
<pre style="font-size:.74rem;margin-top:6px">const compose = (f,g) => x => f(g(x));
const shout = compose(s=>s+'!', s=>s.toUpperCase());
shout('hi'); // "HI!"</pre></div>
<div class="box definition"><h4>Currying</h4>Multi-argument function ko single-argument functions ki chain me todna.
<pre style="font-size:.74rem;margin-top:6px">const add = a => b => a + b;
add(2)(3); // 5 — useful for creating specialized functions</pre></div>
</div>
<div class="box tip"><h4>💡 Why FP matters in real projects</h4>Predictable, testable code. React/Redux dono heavily FP principles use karte hain (pure reducers, immutable updates) — isliye FP samajhna in libraries ko samajhna aasan bana deta hai.</div>
</section>
<!-- ============ 18 ADVANCED JS ============ -->
<section id="advanced" class="reveal">
<span class="eyebrow">18 · Advanced JS</span>
<h2 class="stitle">Advanced JavaScript Internals</h2>
<div class="subhead">🔹 Hoisting — the real mechanism</div>
<pre>console.log(x); <span class="cm">// undefined (NOT an error!) — var is hoisted</span>
<span class="kw">var</span> x = <span class="st">5</span>;
console.log(y); <span class="cm">// ❌ ReferenceError — "Cannot access 'y' before initialization"</span>
<span class="kw">let</span> y = <span class="st">5</span>; <span class="cm">// let/const are hoisted too, but in the "Temporal Dead Zone" (TDZ)</span></pre>
<p style="font-size:.86rem;color:var(--muted)"><b>Internally:</b> JS engine 2 passes karta hai — pehle pass me saari declarations "memory me register" ho jaati hain (hoisting), doosre pass me actual execution hoti hai. <span class="mono">var</span> ko <span class="mono">undefined</span> se initialize kiya jaata hai turant, par <span class="mono">let/const</span> "uninitialized" state me rehte hain (TDZ) jab tak unki actual line na aaye.</p>
<div class="subhead">🔹 Execution Context & Call Stack</div>
<div class="ascii">function three() { console.log('three'); }
function two() { three(); }
function one() { two(); }
one();
Call Stack (grows/shrinks as functions call/return):
┌──────────┐
│ three() │ ← top of stack, executing now
├──────────┤
│ two() │
├──────────┤
│ one() │
├──────────┤
│ Global │ ← always at the bottom
└──────────┘</div>
<p style="font-size:.86rem;color:var(--muted)">Har function call ek naya "Execution Context" stack par push karta hai (apna scope, variables, 'this'). Function return hone par uska context pop ho jaata hai. Bohot deep recursion → stack "overflow" ho jaata hai.</p>
<div class="subhead">🔹 Garbage Collection & Memory Leaks</div>
<p style="font-size:.9rem;color:var(--muted);margin-bottom:8px">JS engine automatically memory free karta hai jab koi object ab "reachable" nahi rehta (kisi variable se reference nahi ho raha). Isko "Mark and Sweep" algorithm kehte hain.</p>
<pre><span class="cm">// Common memory leak — forgotten event listener/timer</span>
<span class="kw">function</span> <span class="fn">setup</span>() {
<span class="kw">const</span> hugeData = <span class="kw">new</span> Array(<span class="st">1000000</span>).fill(<span class="st">'data'</span>);
document.addEventListener(<span class="st">'click'</span>, () => console.log(hugeData.length));
<span class="cm">// listener NEVER removed → hugeData can NEVER be garbage collected, even after component "unmounts"</span>
}</pre>
<div class="box warning"><h4>⚠️ Common leak sources</h4>Forgotten setInterval/addEventListener, closures holding large data unnecessarily, detached DOM nodes still referenced in JS variables.</div>
<div class="subhead">🔹 WeakMap & WeakSet</div>
<pre><span class="kw">const</span> cache = <span class="kw">new</span> WeakMap();
cache.set(someObject, <span class="st">'cached data'</span>);
<span class="cm">// If someObject has no other references, it CAN still be garbage collected —</span>
<span class="cm">// WeakMap doesn't prevent GC, unlike a normal Map. Great for caching without leaks.</span></pre>