Skip to main content

JavaScript (ES6+) topics

🔁 1. Callbacks

  • Goal: Understand how functions can be passed and executed later.

  • Study Plan:

    • Write a function that takes a callback (e.g., simulate an API call).

    • Understand callback hell and how it leads to Promises.


function fetchData(callback) { setTimeout(() => { callback("Data loaded"); }, 1000); } fetchData((data) => console.log(data));

🔄 2. Promises

  • Goal: Handle async operations cleanly.

  • Study Plan:

    • Create basic promises using new Promise().

    • Learn .then(), .catch(), and .finally() chaining.


function fetchData() { return new Promise((resolve, reject) => { setTimeout(() => resolve("Data received"), 1000); }); } fetchData().then(console.log).catch(console.error);

⏳ 3. Async/Await

  • Goal: Write cleaner async code.

  • Study Plan:

    • Convert a promise-based function to async/await.

    • Handle errors using try...catch.


async function loadData() { try { const data = await fetchData(); console.log(data); } catch (err) { console.error(err); } } loadData();

🔧 4. Destructuring

  • Goal: Unpack arrays/objects quickly.

  • Study Plan:

    • Practice array/object destructuring in variables, function parameters, and return values.


const user = { name: "Alice", age: 25 }; const { name, age } = user; console.log(name, age);

➡️ 5. Arrow Functions

  • Goal: Use concise syntax and understand lexical this.

  • Study Plan:

    • Convert regular functions to arrow functions.

    • Understand how this behaves differently.


const greet = () => console.log("Hello!");

📦 6. Modules

  • Goal: Organize code into reusable files.

  • Study Plan:

    • Use export/import syntax.

    • Split functions/constants across files.


// math.js export const add = (a, b) => a + b; // main.js import { add } from './math.js'; console.log(add(2, 3));

Comments

Popular posts from this blog

Freshworks Chennai Full Marathon 2025: A Race That Rebuilt My Confidence

The Freshworks Chennai Full Marathon on January 5th, 2025, with bib number 42495, was more than just another race for me—it was a pivotal moment in my running journey, restoring my confidence after a tough outing in Kolkata and preparing me for my first 50km Tata Ultra. Bouncing Back from Kolkata Leading up to Chennai, my last major race was a 25km event in Kolkata. At the 20km mark, I developed a niggle that turned into pain, forcing me to walk most of the final stretch. That experience left me questioning whether I could hold up beyond 20km—an essential benchmark for marathon and ultra training. Arriving in Chennai: Simple, Focused Preparation I arrived in Chennai from Bangalore the day before the marathon, checked into my hotel, and collected my bib. I kept my pre-race routine simple: light food, early bedtime, and a kit packed with dates and electrolytes. The start line was just 1.5km from my stay, so I jogged over as a warm-up, feeling the early morning energy of the city. R...

Pacing the 2:20 Bus at Tuffman Half Marathon

Bib Number: 21248 Race Date: 2nd February 2025 Event: Tuffman Half Marathon Pacer Goal: 2 Hours 20 Minutes This was my first time officially pacing a race, and what an unforgettable experience it turned out to be! To prepare for pacing the 2:20 bus, I did focused training. I ran two practice half marathons at an even 2:20 pace to internalize the rhythm and effort required. This wasn’t just physical prep—it was special because it trained me to run at a lower heart rate , a valuable skill that’s already helping with my main goal: finishing the Tata Ultra 50K strong. But this race wasn’t just about me. I encouraged three friends from my apartment to join as well—two signed up for the 5K and one bravely stepped into the half marathon distance. I even picked up their bibs and drove them to the race. It was such a unique experience to pull and push first-time runners toward the joy of running. Race Day At the start line, I stood alone with my pacer flag. But just before the gun went...

A Magical Weekend at Akshayakalpa Farm, Tiptur – A Journey into Organic Living

Just a three-hour drive and around 160 km from our home, tucked away in the peaceful green stretches of Tiptur, lies a gem of a place — Akshayakalpa Organic Farm . We had been planning a short weekend getaway, and this one-night, two-day trip turned out to be so much more than just a break from routine. It was an experience — wholesome, inspiring, and refreshing in every sense. Before the Visit: Thoughts & Expectations Before setting off, I had a few ideas in mind. I imagined fresh organic food, a serene countryside escape, and a chance to learn something new about sustainable farming. I expected to enjoy nature, perhaps interact with a few animals, and understand how organic dairy products are made. But what I got was far beyond expectations — it was immersive, educational, and joyful. From start to finish, it felt like a beautiful blend of eco-conscious living, learning, and community bonding. Day 1: Arrival & First Impressions We reached the farm around 10:45 am. Upon a...