JavaScript Topics with Navigation

1. Variables

Definition: Variables store data that can be used later in your program.


// Syntax:
let name = "Alice";
const age = 25;
var city = "Paris";

// Example:
let x = 10;
x = 20;
console.log(x);   // Output: 20
    
⬆️ Back to Top

2. Data Types

Definition: JavaScript supports multiple data types, including string, number, and boolean.


// Syntax:
let str = "Hello";
let num = 123;
let bool = true;

// Example:
console.log(typeof str);   // Output: string
console.log(typeof num);   // Output: number
    
⬆️ Back to Top

3. Operators

Definition: Operators perform operations on variables and values.


// Syntax:
let sum = 5 + 2;
let diff = 10 - 3;

// Example:
let a = 10, b = 5;
console.log(a + b);    // Output: 15
console.log(a > b);    // Output: true
    
⬆️ Back to Top

4. Control Flow (If-Else)

Definition: Used for executing code based on conditions.


// Syntax:
if (condition) {
    // Code if true
} else {
    // Code if false
}

// Example:
let age = 18;
if (age >= 18) {
    console.log("Adult");
} else {
    console.log("Minor");
}
    
⬆️ Back to Top

5. Loops

Definition: Loops are used to repeat a block of code multiple times.


// Syntax:
for (let i = 0; i < 5; i++) {
    console.log(i);
}

// Example:
let j = 0;
while (j < 5) {
    console.log(j);
    j++;
}
    
⬆️ Back to Top

6. Functions

Definition: Functions are reusable blocks of code.


// Syntax:
function greet(name) {
    console.log("Hello " + name);
}

// Example:
greet("Alice");   // Output: Hello Alice
    
⬆️ Back to Top

7. Arrays

Definition: Arrays store multiple values in a single variable.


// Syntax:
let colors = ["Red", "Green", "Blue"];

// Example:
console.log(colors[0]);   // Output: Red
    
⬆️ Back to Top

8. Objects

Definition: Objects store data in key-value pairs.


// Syntax:
let person = {
    name: "Alice",
    age: 25
};

// Example:
console.log(person.name);   // Output: Alice
    
⬆️ Back to Top

9. Events

Definition: Events respond to user interactions.


// Syntax:

    
⬆️ Back to Top

10. DOM Manipulation

Definition: DOM allows JavaScript to manipulate HTML elements.


// Syntax:
document.getElementById("demo").innerHTML = "Hello, DOM!";
    
⬆️ Back to Top

11. Error Handling

Definition: Manages runtime errors.


try {
    let x = y;    
} catch (error) {
    console.log("Error occurred: " + error);
}
    
⬆️ Back to Top

12. ES6 Features

Definition: New JS features like arrow functions.


const greet = (name) => `Hello, ${name}`;
console.log(greet("Alice"));
    
⬆️ Back to Top

13. Promises


let promise = new Promise((resolve, reject) => {
    resolve("Done");
});
    
⬆️ Back to Top