JavaScript Learning Path

A comprehensive guide to mastering JavaScript from fundamentals to advanced concepts

Introduction to JavaScript
Learn what JavaScript is and why it's important for web development

JavaScript is a high-level, interpreted programming language that is one of the core technologies of the web. It allows you to add interactivity to websites, create web applications, and even build server-side applications.

Your First JavaScript Code

javascript
1// This is a comment
2console.log("Hello, World!"); // Prints to the console
3
4// You can also use alert to show a popup
5// alert("Hello from JavaScript!");

Pro Tip

You can open your browser's developer tools (F12 or Right-click → Inspect) to see console output.

Variables and Data Types
Learn how to store and manipulate data in JavaScript

Declaring Variables

JavaScript has three ways to declare variables: var, let, and const.

javascript
1// var (older way, function scoped)
2var name = "John";
3
4// let (block scoped, can be reassigned)
5let age = 25;
6age = 26; // This is valid
7
8// const (block scoped, cannot be reassigned)
9const PI = 3.14159;
10// PI = 3.14; // This would cause an error

Data Types

JavaScript has several primitive data types and one complex data type (Object).

javascript
1// Primitive types
2let string = "Hello"; // String
3let number = 42; // Number
4let decimal = 3.14; // Also a Number
5let boolean = true; // Boolean
6let nullValue = null; // Null
7let undefinedValue; // Undefined
8let bigInt = 9007199254740991n; // BigInt
9let symbol = Symbol("unique"); // Symbol
10
11// Check the type using typeof
12console.log(typeof string); // "string"
13console.log(typeof number); // "number"
14console.log(typeof boolean); // "boolean"
15
16// Complex type: Object
17let person = {
18 name: "Alice",
19 age: 30,
20 isStudent: false
21};
22
23// Arrays are also objects
24let fruits = ["apple", "banana", "orange"];
25
26console.log(typeof person); // "object"
27console.log(typeof fruits); // "object"
28console.log(Array.isArray(fruits)); // true
Operators and Expressions
Learn how to perform operations on values

Arithmetic Operators

javascript
1let a = 10;
2let b = 3;
3
4console.log(a + b); // Addition: 13
5console.log(a - b); // Subtraction: 7
6console.log(a * b); // Multiplication: 30
7console.log(a / b); // Division: 3.3333...
8console.log(a % b); // Modulus (remainder): 1
9console.log(a ** b); // Exponentiation: 1000 (10^3)
10
11// Increment and decrement
12let c = 5;
13console.log(c++); // 5 (returns c, then increments)
14console.log(c); // 6
15console.log(++c); // 7 (increments c, then returns it)

Comparison Operators

javascript
1let x = 5;
2let y = "5";
3
4console.log(x == y); // true (loose equality, converts types)
5console.log(x === y); // false (strict equality, checks types)
6console.log(x != y); // false (loose inequality)
7console.log(x !== y); // true (strict inequality)
8console.log(x > 3); // true
9console.log(x <= 5); // true

Logical Operators

javascript
1let isAdult = true;
2let hasLicense = false;
3
4console.log(isAdult && hasLicense); // AND: false
5console.log(isAdult || hasLicense); // OR: true
6console.log(!isAdult); // NOT: false
7
8// Short-circuit evaluation
9let name = "";
10let defaultName = name || "Anonymous"; // "Anonymous"
11
12let user = { name: "John" };
13let userName = user && user.name; // "John"
Control Flow
Learn how to control the flow of your program with conditionals and loops

Conditional Statements

javascript
1let age = 18;
2
3// if statement
4if (age >= 18) {
5 console.log("You are an adult");
6}
7
8// if-else statement
9if (age >= 18) {
10 console.log("You are an adult");
11} else {
12 console.log("You are a minor");
13}
14
15// if-else if-else statement
16if (age < 13) {
17 console.log("Child");
18} else if (age < 18) {
19 console.log("Teenager");
20} else {
21 console.log("Adult");
22}
23
24// Ternary operator (condition ? trueValue : falseValue)
25let status = age >= 18 ? "Adult" : "Minor";
26console.log(status);
27
28// Switch statement
29let day = 2;
30switch (day) {
31 case 0:
32 console.log("Sunday");
33 break;
34 case 1:
35 console.log("Monday");
36 break;
37 case 2:
38 console.log("Tuesday");
39 break;
40 default:
41 console.log("Another day");
42}

Loops

javascript
1// for loop
2for (let i = 0; i < 5; i++) {
3 console.log("Iteration " + i);
4}
5
6// while loop
7let count = 0;
8while (count < 3) {
9 console.log("Count: " + count);
10 count++;
11}
12
13// do-while loop (always executes at least once)
14let num = 0;
15do {
16 console.log("Number: " + num);
17 num++;
18} while (num < 3);
19
20// for...of loop (iterates over iterable values)
21const colors = ["red", "green", "blue"];
22for (const color of colors) {
23 console.log(color);
24}
25
26// for...in loop (iterates over object properties)
27const person = { name: "John", age: 30, job: "developer" };
28for (const key in person) {
29 console.log(key + ": " + person[key]);
30}