-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodelab-javascript.html
More file actions
1010 lines (842 loc) · 36.7 KB
/
codelab-javascript.html
File metadata and controls
1010 lines (842 loc) · 36.7 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>Ai CodeLab - Core Documentation</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Modern Styles -->
<link rel="stylesheet" href="styles.css">
<style>
.study-grid {
display: grid;
grid-template-columns: 3fr 1fr;
gap: 3rem;
max-width: 1400px;
margin: 0 auto;
}
.study-content {
background: linear-gradient(135deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
border: 1px solid var(--glass-border);
border-radius: 20px;
padding: 3rem;
backdrop-filter: blur(20px);
color: var(--text-pure);
}
.study-content h1, .study-content h2, .study-content h3 {
color: var(--secondary);
margin-top: 2.5rem;
margin-bottom: 1rem;
border-bottom: 1px solid var(--glass-border);
padding-bottom: 0.5rem;
}
.study-content h1 {
color: var(--primary);
font-size: 3rem;
}
.study-content p, .study-content li {
margin-bottom: 1.2rem;
color: var(--text-muted);
line-height: 1.8;
font-size: 1.05rem;
}
.study-content ul, .study-content ol {
margin-left: 2rem;
margin-bottom: 2rem;
}
.study-content pre {
background: rgba(0,0,0,0.6);
border: 1px solid var(--glass-border);
padding: 1.5rem;
border-radius: 10px;
overflow-x: auto;
margin-bottom: 2rem;
color: var(--accent);
font-family: monospace;
box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}
.study-sidebar {
background: linear-gradient(135deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
border: 1px solid var(--glass-border);
border-radius: 20px;
padding: 2rem;
backdrop-filter: blur(20px);
position: sticky;
top: 100px;
height: fit-content;
}
.study-sidebar h2 {
color: var(--primary);
margin-bottom: 1.5rem;
border-bottom: 1px solid var(--glass-border);
padding-bottom: 0.5rem;
font-size: 1.2rem;
}
.study-sidebar a {
display: flex;
align-items: center;
gap: 1rem;
padding: 0.5rem 0;
color: var(--text-muted);
transition: all 0.3s;
}
.study-sidebar a:hover {
color: var(--secondary);
transform: translateX(5px);
}
@media (max-width: 900px) {
.study-grid { grid-template-columns: 1fr; }
.study-sidebar { position: relative; top: 0; }
}
</style>
</head>
<body>
<!-- Custom Cursor -->
<div id="custom-cursor"></div>
<!-- Animated Mesh Gradient Background -->
<div class="mesh-bg">
<div class="blob blob-1"></div>
<div class="blob blob-2"></div>
<div class="blob blob-3"></div>
</div>
<!-- Modern Extreme Navbar -->
<nav>
<div class="logo-container">
<i class="fas fa-robot"></i>
<span>CodeLab<span style="color:var(--primary)">.ai</span></span>
</div>
<div class="nav-links">
<a href="index.html">Platform</a>
<a href="courses.html">Syllabus</a>
<a href="study.html" class="active">Resources</a>
<a href="join.html">Community</a>
</div>
<div style="display:flex;gap:10px;">
<a href="login.html" class="magnetic-btn" style="padding: 0.5rem 1.5rem; font-size: 0.9rem;"><span>Login</span></a>
</div>
</nav>
<!-- Page Title Header -->
<header style="margin-top: 120px; text-align: center; padding: 2rem;">
<h1 class="hover-target" style="font-size: clamp(2.5rem, 5vw, 4rem);"><span class="gradient-text">Protocol</span> Documentation</h1>
</header>
<main style="padding: 2rem;">
<div class="study-grid">
<div class="study-content reveal hover-target" data-tilt>
<!-- <section id="introduction">
<h1>Introduction</h1>
<p>Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.</p>
</section> -->
<section id="introduction">
<h1>Introduction</h1>
<p>JavaScript is a high-level, dynamic programming language that enables interactive and dynamic web development. It is widely used for client-side scripting, enhancing user experience through interactive elements, animations, and real-time updates.</p>
</section>
<!-- <section id="history">
<h2>History & Evolution</h2>
<p>Java was developed by James Gosling at Sun Microsystems and released in 1995. It has since become one of the most popular programming languages in the world.</p>
</section> -->
<section id="history">
<h2>History & Evolution</h2>
<p>JavaScript was created by Brendan Eich at Netscape and released in 1995. Originally developed in just 10 days, it has evolved into a powerful language that drives modern web development, powering interactive and dynamic web applications.</p>
</section>
<section id="why-learn-js">
<h2>Why Learn JavaScript?</h2>
<p>JavaScript is one of the most popular and useful programming languages. Here’s why you should learn it:</p>
<ul>
<li><strong>Easy to Learn:</strong> JavaScript has a simple syntax, making it beginner-friendly.</li>
<li><strong>Works in Browsers:</strong> No need to install anything! JavaScript runs directly in web browsers.</li>
<li><strong>Makes Websites Interactive:</strong> You can create buttons, animations, pop-ups, and more.</li>
<li><strong>High Demand:</strong> Many companies hire JavaScript developers for web development.</li>
<li><strong>Used Everywhere:</strong> JavaScript is used for websites, mobile apps, games, and even servers.</li>
<li><strong>Huge Community:</strong> Many tutorials, forums, and resources are available to help you learn.</li>
<li><strong>Build Amazing Projects:</strong> You can create websites, web apps, and interactive games!</li>
</ul>
</section>
<section id="installing-js">
<h2>Installing JavaScript</h2>
<p>The best part about JavaScript is that you don’t need to install anything! It runs directly in your web browser. Follow these simple steps to start using JavaScript:</p>
<h3>1. Use Your Web Browser</h3>
<p>Every modern web browser (Chrome, Firefox, Edge) has a built-in JavaScript engine. You can write and test JavaScript in the browser console.</p>
<p><strong>How to open the console?</strong></p>
<ul>
<li><strong>Google Chrome:</strong> Press <code>Ctrl + Shift + J</code> (Windows) or <code>Cmd + Option + J</code> (Mac).</li>
<li><strong>Firefox:</strong> Press <code>Ctrl + Shift + K</code> (Windows) or <code>Cmd + Option + K</code> (Mac).</li>
</ul>
<h3>2. Create a Simple JavaScript File</h3>
<p>You can write JavaScript in a text editor like Notepad, VS Code, or Sublime Text.</p>
<p>Save a file as <code>script.js</code> and write this code:</p>
<pre><code>console.log("Hello, JavaScript!");</code></pre>
<h3>3. Run JavaScript in an HTML File</h3>
<p>Create an HTML file (e.g., <code>index.html</code>) and link your JavaScript file like this:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<title>JavaScript Test</title>
</head>
<body>
<h1>JavaScript is working!</h1>
<script src="script.js"></script>
</body>
</html></code></pre>
<p>Open <code>index.html</code> in a browser, and you’ll see the output in the console!</p>
<h3>That's It!</h3>
<p>Now you’re ready to start coding in JavaScript! 🎉</p>
</section>
<section id="JavaScript Basics">
<h2>JavaScript Basics</h2>
<p>JavaScript is a powerful and easy-to-learn programming language used to make websites interactive. It allows you to display messages, handle user actions, and perform calculations. The basics of JavaScript include variables, which store data like text and numbers, operators, which help perform math operations, and conditions like if-else that help make decisions in code. Loops allow repeating tasks, while functions help create reusable blocks of code. JavaScript can also respond to user actions, like clicking a button or typing in a form. By learning these basics, you can start building dynamic and interactive web pages easily! 🚀</p>
</section>
<section id="variables-data-types">
<h2>Variables & Data Types</h2>
<h3>Variables in JavaScript</h3>
<p>Variables are containers for storing data. In JavaScript, we have three ways to declare variables:</p>
<pre><code>// Using let (recommended for variables that can change)
let age = 25;
// Using const (for values that won't change)
const PI = 3.14159;
// Using var (older way, try to avoid)
var name = "John";</code></pre>
<h3>Data Types</h3>
<p>JavaScript has several basic data types:</p>
<h4>1. Primitive Data Types</h4>
<pre><code>// String - for text
let name = "John";
let message = 'Hello World';
// Number - for both integers and decimals
let age = 25;
let price = 99.99;
// Boolean - true or false
let isStudent = true;
let isWorking = false;
// Undefined - variable declared but no value assigned
let undefinedVar;
// Null - intentionally empty value
let emptyValue = null;
// Symbol - unique identifier
let symbol = Symbol('description');</code></pre>
<h4>2. Complex Data Types</h4>
<pre><code>// Array - ordered list of items
let colors = ['red', 'green', 'blue'];
let numbers = [1, 2, 3, 4, 5];
// Object - collection of key-value pairs
let person = {
name: "John",
age: 25,
isStudent: true
};</code></pre>
<h3>Checking Data Types</h3>
<pre><code>// Using typeof operator
console.log(typeof "Hello"); // "string"
console.log(typeof 42); // "number"
console.log(typeof true); // "boolean"
console.log(typeof undefined); // "undefined"
console.log(typeof null); // "object"
console.log(typeof {}); // "object"
console.log(typeof []); // "object"</code></pre>
<h3>Common Operations with Variables</h3>
<pre><code>// String concatenation
let firstName = "John";
let lastName = "Doe";
let fullName = firstName + " " + lastName; // "John Doe"
// Template literals (modern way)
let greeting = `Hello, ${firstName}!`; // "Hello, John!"
// Working with numbers
let x = 10;
let y = 5;
let sum = x + y; // 15
let product = x * y; // 50
// Type conversion
let numStr = "42";
let num = Number(numStr); // converts string to number
let str = String(num); // converts number to string
let bool = Boolean(1); // converts to boolean</code></pre>
<h3>Best Practices</h3>
<ul>
<li>Use <code>const</code> by default, and <code>let</code> when you need to reassign values</li>
<li>Avoid using <code>var</code> as it can lead to scope issues</li>
<li>Use meaningful variable names that describe their purpose</li>
<li>Be consistent with your naming conventions (camelCase is common in JavaScript)</li>
<li>Initialize variables when you declare them</li>
</ul>
<div class="practice-example">
<h3>Practice Example</h3>
<pre><code>// Creating a simple user profile
const user = {
firstName: "Alice",
lastName: "Smith",
age: 28,
isAdmin: false,
skills: ["JavaScript", "HTML", "CSS"],
contact: {
email: "alice@example.com",
phone: null
}
};
// Accessing and using the data
console.log(`User: ${user.firstName} ${user.lastName}`);
console.log(`Age: ${user.age}`);
console.log(`Skills: ${user.skills.join(", ")}`);
console.log(`Is admin? ${user.isAdmin ? "Yes" : "No"}`);</code></pre>
</div>
</section>
<section id="operators">
<h2><i class="fas fa-calculator"></i> Operators in JavaScript</h2>
<p>Operators are special symbols that help us perform operations like math calculations, comparing values, or combining conditions. Let's learn the most common ones! 🎯</p>
<h3>1. Arithmetic Operators (Math)</h3>
<pre><code>// Basic Math Operations
let a = 10;
let b = 5;
let sum = a + b; // Addition: 15
let diff = a - b; // Subtraction: 5
let product = a * b; // Multiplication: 50
let quotient = a / b; // Division: 2
let remainder = a % b;// Remainder (Modulus): 0
// Increment and Decrement
let count = 1;
count++; // Adds 1 (count is now 2)
count--; // Subtracts 1 (count is back to 1)</code></pre>
<h3>2. Assignment Operators</h3>
<pre><code>let x = 10; // Basic assignment
x += 5; // Same as: x = x + 5 (x is now 15)
x -= 3; // Same as: x = x - 3 (x is now 12)
x *= 2; // Same as: x = x * 2 (x is now 24)
x /= 4; // Same as: x = x / 4 (x is now 6)</code></pre>
<h3>3. Comparison Operators</h3>
<pre><code>// Compare values and get true or false
let num1 = 5;
let num2 = 10;
let text = "5";
console.log(num1 == text); // true (checks only value)
console.log(num1 === text); // false (checks value AND type)
console.log(num1 < num2); // true
console.log(num1 >= 5); // true
console.log(num1 != num2); // true (not equal)</code></pre>
<h3>4. Logical Operators</h3>
<pre><code>// Combine conditions
let isStudent = true;
let hasDiscount = false;
// AND operator (&&) - both must be true
console.log(isStudent && hasDiscount); // false
// OR operator (||) - at least one must be true
console.log(isStudent || hasDiscount); // true
// NOT operator (!) - reverses true/false
console.log(!isStudent); // false</code></pre>
<h3>5. String Operators</h3>
<pre><code>// Combining text
let firstName = "John";
let lastName = "Doe";
// Using + to join strings
let fullName = firstName + " " + lastName; // "John Doe"
// Modern way using template literals
let greeting = `Hello, ${firstName}!`; // "Hello, John!"</code></pre>
<div class="practice-example">
<h3>🎯 Practice Example: Shopping Cart</h3>
<pre><code>// Shopping cart calculation
const price = 99.99;
const quantity = 2;
const discount = 10; // 10% discount
// Calculate total
let total = price * quantity; // Multiplication
let savings = (total * discount) / 100; // Calculate discount
let finalPrice = total - savings; // Apply discount
console.log(`Price per item: $${price}`);
console.log(`Quantity: ${quantity}`);
console.log(`Subtotal: $${total}`);
console.log(`Discount: $${savings}`);
console.log(`Final Price: $${finalPrice}`);</code></pre>
</div>
<h3>💡 Tips for Using Operators</h3>
<ul>
<li>Always use <code>===</code> instead of <code>==</code> for comparing values (strict equality)</li>
<li>Be careful with division by zero</li>
<li>Use parentheses <code>()</code> to make your calculations clear</li>
<li>Remember that <code>+</code> can add numbers or join strings</li>
<li>Test your conditions with different values to make sure they work as expected</li>
</ul>
</section>
<section id="control-flow">
<h2><i class="fas fa-random"></i> Control Flow in JavaScript</h2>
<p>Control flow helps us make decisions and repeat actions in our code. Let's see some simple examples! 🎮</p>
<h3>1. If Statements</h3>
<pre><code>// Simple age check
let age = 15;
if (age >= 18) {
console.log("You are an adult");
} else {
console.log("You are a minor");
}</code></pre>
<h3>2. Switch Statement</h3>
<pre><code>// Check day of the week
let day = "Monday";
switch (day) {
case "Monday": console.log("Work day");
break;
default: console.log("Regular day");
}</code></pre>
<h3>3. For Loop</h3>
<pre><code>// Count from 1 to 3
for (let i = 1; i <= 3; i++) {
console.log(`Number ${i}`);
}</code></pre>
<h3>4. While Loop</h3>
<pre><code>// Simple countdown
let count = 3;
while (count > 0) {
console.log(count);
count--;
}</code></pre>
<div class="practice-example">
<h3>🎯 Simple Practice Example</h3>
<pre><code>// Check if a number is positive or negative
let number = 5;
if (number > 0) {
console.log("Positive");
} else {
console.log("Zero or Negative");
}</code></pre>
</div>
<h3>💡 Tips</h3>
<ul>
<li>Use <code>if</code> for simple decisions</li>
<li>Use <code>for</code> when you know how many times to repeat</li>
<li>Use <code>while</code> when you don't know how many times to repeat</li>
<li>Keep your conditions simple</li>
</ul>
</section>
<section id="control-flow">
<h2><i class="fas fa-random"></i> Control Flow in JavaScript</h2>
<p>Control flow helps us make decisions and repeat actions in our code. Let's see some simple examples! 🎮</p>
<h3>1. If Statements</h3>
<pre><code>// Simple age check
let age = 15;
if (age >= 18) {
console.log("You are an adult");
} else {
console.log("You are a minor");
}</code></pre>
<h3>2. Switch Statement</h3>
<pre><code>// Check day of the week
let day = "Monday";
switch (day) {
case "Monday": console.log("Work day");
break;
default: console.log("Regular day");
}</code></pre>
<h3>3. For Loop</h3>
<pre><code>// Count from 1 to 3
for (let i = 1; i <= 3; i++) {
console.log(`Number ${i}`);
}</code></pre>
<h3>4. While Loop</h3>
<pre><code>// Simple countdown
let count = 3;
while (count > 0) {
console.log(count);
count--;
}</code></pre>
<div class="practice-example">
<h3>🎯 Simple Practice Example</h3>
<pre><code>// Check if a number is positive or negative
let number = 5;
if (number > 0) {
console.log("Positive");
} else {
console.log("Zero or Negative");
}</code></pre>
</div>
<h3>💡 Tips</h3>
<ul>
<li>Use <code>if</code> for simple decisions</li>
<li>Use <code>for</code> when you know how many times to repeat</li>
<li>Use <code>while</code> when you don't know how many times to repeat</li>
<li>Keep your conditions simple</li>
</ul>
</section>
<section id="functions">
<h2><i class="fas fa-code"></i> Functions in JavaScript</h2>
<p>Functions are like recipes - they help us reuse code and perform tasks. Let's see some simple examples! 🚀</p>
<h3>1. Basic Function</h3>
<pre><code>// Simple greeting function
function sayHello(name) {
return "Hello, " + name;
}
console.log(sayHello("John")); // Output: Hello, John</code></pre>
<h3>2. Arrow Function</h3>
<pre><code>// Modern way to write functions
const add = (a, b) => a + b;
console.log(add(5, 3)); // Output: 8</code></pre>
<h3>3. Function with Default Value</h3>
<pre><code>// Function with default parameter
const greet = (name = "Guest") => "Welcome, " + name;
console.log(greet()); // Output: Welcome, Guest</code></pre>
<div class="practice-example">
<h3>🎯 Practice Example</h3>
<pre><code>// Calculate discount
const getDiscount = (price, discount) => {
return price - (price * discount / 100);
}
console.log(getDiscount(100, 10)); // Output: 90</code></pre>
</div>
<h3>💡 Tips</h3>
<ul>
<li>Keep functions small and focused</li>
<li>Use clear function names</li>
<li>Arrow functions are great for short operations</li>
<li>Always test your functions</li>
</ul>
</section>
<section id="arrays">
<h2><i class="fas fa-list"></i> Arrays in JavaScript</h2>
<p>Arrays are like lists that can store multiple items in a single variable. Let's learn how to use them! 📝</p>
<h3>1. Creating Arrays</h3>
<pre><code>// Simple array of numbers
let numbers = [1, 2, 3, 4, 5];
// Array of strings
let colors = ['red', 'green', 'blue'];</code></pre>
<h3>2. Accessing Array Elements</h3>
<pre><code>// Arrays start counting from 0
let fruits = ['apple', 'banana', 'orange'];
console.log(fruits[0]); // Output: apple
console.log(fruits[1]); // Output: banana</code></pre>
<h3>3. Common Array Methods</h3>
<pre><code>// Add and remove items
let team = ['John', 'Mary'];
team.push('Bob'); // Add to end
team.pop(); // Remove from end
team.unshift('Alice'); // Add to start
team.shift(); // Remove from start</code></pre>
<div class="practice-example">
<h3>🎯 Practice Example: Todo List</h3>
<pre><code>// Simple todo list
let todos = ['Study JS', 'Do homework'];
// Add new todo
todos.push('Take a break');
// Mark first todo as done
todos[0] = '✅ Study JS';</code></pre>
</div>
<h3>💡 Quick Tips</h3>
<ul>
<li>Arrays can store any type of data</li>
<li>Use <code>length</code> to get array size</li>
<li>Use <code>push()</code> to add items</li>
<li>Use <code>[]</code> to access items</li>
</ul>
</section>
<section id="objects">
<h2><i class="fas fa-cube"></i> Objects in JavaScript</h2>
<p>Objects are like containers that store related data and functions. Think of them as a way to describe something with its properties! 📦</p>
<h3>1. Creating Objects</h3>
<pre><code>// Simple person object
let person = {
name: "John",
age: 25,
isStudent: true
};</code></pre>
<h3>2. Accessing Object Properties</h3>
<pre><code>// Two ways to access properties
console.log(person.name); // Using dot notation
console.log(person["age"]); // Using bracket notation</code></pre>
<div class="practice-example">
<h3>🎯 Simple Practice Example</h3>
<pre><code>// Create a car object
let car = {
brand: "Toyota",
model: "Camry",
start: function() {
console.log("Car started!");
}
};
car.start(); // Output: Car started!</code></pre>
</div>
</section>
<section id="dom">
<h2><i class="fas fa-code"></i> DOM Manipulation</h2>
<p>DOM (Document Object Model) lets you change webpage content using JavaScript. Let's see how! 🎨</p>
<h3>1. Selecting Elements</h3>
<pre><code>// Get element by ID
let title = document.getElementById("main-title");
// Get elements by class name
let items = document.getElementsByClassName("item");</code></pre>
<h3>2. Changing Content</h3>
<pre><code>// Change text content
title.textContent = "New Title";
// Change HTML content
title.innerHTML = "New <span>Title</span>";</code></pre>
<div class="practice-example">
<h3>🎯 Try This Example</h3>
<button onclick="changeColor()" id="colorButton">Change My Color</button>
<pre><code>// Change button color
function changeColor() {
let button = document.getElementById("colorButton");
button.style.backgroundColor = "blue";
}</code></pre>
</div>
</section>
<section id="events">
<h2><i class="fas fa-bolt"></i> Events in JavaScript</h2>
<p>Events let you make your webpage interactive by responding to user actions like clicks and key presses! ⚡</p>
<h3>1. Click Events</h3>
<pre><code>// Simple click event
let button = document.getElementById("myButton");
button.onclick = function() {
alert("Button clicked!");
};</code></pre>
<h3>2. Common Events</h3>
<pre><code>// Mouse over event
element.onmouseover = function() {
console.log("Mouse is over!");
};
// Key press event
input.onkeypress = function() {
console.log("Key pressed!");
};</code></pre>
<div class="practice-example">
<h3>🎯 Interactive Example</h3>
<button id="counterBtn">Click Me: 0</button>
<pre><code>// Simple counter
let count = 0;
let btn = document.getElementById("counterBtn");
btn.onclick = function() {
count++;
btn.textContent = `Click Me: ${count}`;
};</code></pre>
</div>
<h3>💡 Quick Tips</h3>
<ul>
<li>Events make your website interactive</li>
<li>Always test your event handlers</li>
<li>Keep event functions simple</li>
<li>Use clear names for your functions</li>
</ul>
</section>
<section id="async">
<h2><i class="fas fa-sync"></i> Async Programming</h2>
<p>Async programming helps us handle tasks that take time, like loading data or images. Let's see some simple examples! ⏰</p>
<h3>1. Promises</h3>
<pre><code>// Simple Promise example
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.log('Error:', error));</code></pre>
<h3>2. Async/Await</h3>
<pre><code>// Modern way to handle async code
async function getData() {
try {
let response = await fetch('https://api.example.com/data');
let data = await response.json();
console.log(data);
} catch (error) {
console.log('Error:', error);
}
}</code></pre>
<div class="practice-example">
<h3>🎯 Simple Timer Example</h3>
<pre><code>// Wait for 2 seconds
function delay(seconds) {
return new Promise(resolve => {
setTimeout(resolve, seconds * 1000);
});
}
async function startTimer() {
console.log('Starting...');
await delay(2);
console.log('2 seconds passed!');
}</code></pre>
</div>
</section>
<section id="es6">
<h2><i class="fas fa-code"></i> ES6+ Features</h2>
<p>ES6+ brings modern features that make JavaScript easier to write. Here are the most useful ones! 🌟</p>
<h3>1. Template Literals</h3>
<pre><code>// Old way
let name = "John";
let msg = "Hello " + name;
// New way
let message = `Hello ${name}`;</code></pre>
<h3>2. Arrow Functions</h3>
<pre><code>// Old way
function add(a, b) {
return a + b;
}
// New way
const add = (a, b) => a + b;</code></pre>
<h3>3. Destructuring</h3>
<pre><code>// Get values from objects
const user = { name: 'John', age: 25 };
const { name, age } = user;
// Get values from arrays
const colors = ['red', 'green'];
const [first, second] = colors;</code></pre>
</section>
<section id="debugging">
<h2><i class="fas fa-bug"></i> Debugging JavaScript</h2>
<p>Finding and fixing errors is part of programming. Here's how to debug your code! 🔍</p>
<h3>1. Console Methods</h3>
<pre><code>// Print simple message
console.log('Hello');
// Print error message
console.error('Something went wrong!');
// Print warning
console.warn('Be careful!');</code></pre>
<h3>2. Try-Catch</h3>
<pre><code>// Handle errors safely
try {
// Code that might fail
doSomething();
} catch (error) {
console.log('Error:', error);
}</code></pre>
<div class="practice-example">
<h3>🎯 Debugging Example</h3>
<pre><code>function divide(a, b) {
if (b === 0) {
console.error('Cannot divide by zero!');
return;
}
console.log(`Result: ${a / b}`);
}
divide(10, 2); // Result: 5
divide(10, 0); // Error: Cannot divide by zero!</code></pre>
</div>
<h3>💡 Debugging Tips</h3>
<ul>
<li>Use <code>console.log()</code> to check values</li>
<li>Check the browser console for errors</li>
<li>Use descriptive error messages</li>
<li>Test your code with different values</li>
</ul>
</section>
<section id="best-practices">
<h2><i class="fas fa-check-circle"></i> JavaScript Best Practices</h2>
<p>Follow these simple tips to write better JavaScript code! 🎯</p>
<h3>1. Naming Conventions</h3>
<pre><code>// Good naming examples
let userName = "John";
const maxCount = 100;
function calculateTotal() { }
// Bad naming examples
let x = "John";
const a = 100;
function calc() { }</code></pre>
<h3>2. Code Organization</h3>
<pre><code>// Group related code together
const userSettings = {
theme: 'dark',
fontSize: 16,
showNotifications: true
};
// Use clear function names
function updateUserProfile() {
// Code here
}</code></pre>
<h3>💡 Quick Tips</h3>
<ul>
<li>Use meaningful variable names</li>
<li>Add comments to explain complex code</li>
<li>Keep functions small and focused</li>
<li>Test your code regularly</li>
<li>Use modern JavaScript features</li>
</ul>
</section>
<section id="frameworks">
<h2><i class="fas fa-layer-group"></i> Popular JavaScript Frameworks</h2>
<p>These tools help you build websites and apps faster! 🚀</p>
<h3>1. Most Popular Frameworks</h3>
<ul>
<li><strong>React</strong> - For building user interfaces</li>
<li><strong>Vue.js</strong> - Easy to learn, great for small to large projects</li>
<li><strong>Angular</strong> - Full-featured framework for large applications</li>
</ul>
<h3>2. Useful Libraries</h3>
<pre><code>// Using jQuery (popular library)
$("#button").click(function() {
alert("Clicked!");
});
// Using Moment.js (date library)
const today = moment().format('YYYY-MM-DD');</code></pre>
<div class="practice-example">
<h3>🎯 Framework Example (React)</h3>
<pre><code>// Simple React component
function Welcome() {
return <h1>Hello, React!</h1>;
}</code></pre>
</div>
</section>
<section id="conclusion">
<h2><i class="fas fa-flag-checkered"></i> Conclusion</h2>
<p>Congratulations on learning JavaScript! Let's recap what we've covered: 🎉</p>
<h3>What You've Learned</h3>
<ul>
<li><strong>Basics:</strong> Variables, data types, and operators</li>
<li><strong>Control Flow:</strong> If statements, loops, and functions</li>
<li><strong>Data Structures:</strong> Arrays and objects</li>
<li><strong>DOM:</strong> Manipulating web pages</li>
<li><strong>Events:</strong> Handling user interactions</li>
<li><strong>Modern JS:</strong> ES6+ features and async programming</li>
</ul>
<h3>Next Steps</h3>
<ul>
<li>Practice with small projects</li>
<li>Learn a framework (React, Vue, or Angular)</li>
<li>Join coding communities</li>
<li>Build your own web applications</li>
</ul>
<div class="practice-example">
<h3>🌟 Your First Project Idea</h3>
<pre><code>// Create a simple todo app
let todos = [];
function addTodo(task) {
todos.push(task);
console.log("Added:", task);
}
function showTodos() {
console.log("My Todos:", todos);
}</code></pre>
</div>
<h3>💡 Final Tips</h3>
<ul>
<li>Code regularly to improve</li>
<li>Don't be afraid to make mistakes</li>
<li>Learn from other developers</li>
<li>Keep exploring new features</li>
<li>Have fun coding! 😊</li>
</ul>
</section>
</code></pre>
</section>\n </div>\n <aside class="study-sidebar reveal">\n<h2><i class="fas fa-list-alt"></i> Article Topics</h2>
<a href="#introduction"><i class="fas fa-book"></i> Introduction to JavaScript</a>
<a href="#why-learn-js"><i class="fas fa-book"></i> Why Learn JavaScript?</a>
<a href="#installing-js"><i class="fas fa-book"></i> Setting Up JavaScript</a>
<a href="#js-basics"><i class="fas fa-book"></i> JavaScript Basics</a>
<a href="#variables-data-types"><i class="fas fa-book"></i> Variables & Data Types</a>
<a href="#operators"><i class="fas fa-book"></i> Operators</a>
<a href="#control-flow"><i class="fas fa-book"></i> Control Flow</a>
<a href="#functions"><i class="fas fa-book"></i> Functions</a>
<a href="#arrays"><i class="fas fa-book"></i> Arrays</a>
<a href="#objects"><i class="fas fa-book"></i> Objects</a>
<a href="#dom"><i class="fas fa-book"></i> DOM Manipulation</a>
<a href="#events"><i class="fas fa-book"></i> Events</a>
<a href="#async"><i class="fas fa-book"></i> Async Programming</a>
<a href="#es6"><i class="fas fa-book"></i> ES6+ Features</a>
<a href="#debugging"><i class="fas fa-book"></i> Debugging</a>
<a href="#best-practices"><i class="fas fa-book"></i> Best Practices</a>
<a href="#frameworks"><i class="fas fa-book"></i> Frameworks & Libraries</a>
<a href="#conclusion"><i class="fas fa-book"></i> Conclusion</a>\n </aside>
</div>
</div>
</main>
<!-- Footer -->
<footer>
<div class="footer-grid reveal">
<div>
<h2 class="footer-logo">CodeLab<span style="color:var(--primary)">.ai</span></h2>