Back to Modules

JavaScript Tutorial

Master JavaScript programming with our comprehensive tutorial. Learn modern JavaScript features and asynchronous programming through examples.

Full Playlist (Watch on Youtube)

Introduction to JavaScript

JavaScript is a versatile programming language that enables interactive web pages and is essential for modern web development.

Examples:

// Hello World in JavaScript
console.log("Hello World!");

document.getElementById("demo").innerHTML = "Hello World!";

Different ways to output Hello World in JavaScript

JavaScript Basics

Learn fundamental JavaScript concepts including variables, data types, and basic operations.

Examples:

// Variables and data types
let number = 42;
const pi = 3.14159;
let isValid = true;
let name = "John";

// Modern ES6+ features
const template = `Hello ${name}`;
const [x, y] = [1, 2]; // Array destructuring
const { age, email } = person; // Object destructuring

Variables, data types, and modern JavaScript features

// Arrays and Objects
const numbers = [1, 2, 3, 4, 5];
const person = {
    name: "John",
    age: 30,
    greet() {
        console.log(`Hello, I'm ${this.name}`);
    }
};

// Array methods
const doubled = numbers.map(n => n * 2);
const sum = numbers.reduce((a, b) => a + b, 0);

Working with arrays and objects in JavaScript

Functions in JavaScript

JavaScript functions are first-class objects and can be used in various ways.

Examples:

// Function declarations
function greet(name) {
    return `Hello, ${name}!`;
}

// Arrow functions
const multiply = (a, b) => a * b;

// Higher-order functions
const twice = (f) => (x) => f(f(x));
const addOne = x => x + 1;
console.log(twice(addOne)(5)); // 7

Different ways to work with functions in JavaScript

Asynchronous JavaScript

Learn how to handle asynchronous operations using Promises and async/await.

Examples:

// Promises
fetch('https://api.example.com/data')
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error(error));

// Async/Await
async function fetchData() {
    try {
        const response = await fetch('https://api.example.com/data');
        const data = await response.json();
        console.log(data);
    } catch (error) {
        console.error(error);
    }
}

Working with Promises and async/await in JavaScript