JavaScript Advanced

Closures and scope, asynchronous JS (promises/async-await) and modules.

3 lessons 5 tasks ⚡ Live compiler
Lessons Compiler Quiz Certificate

📚 Lessons

1 Closures & scope

A closure is a function that remembers variables from where it was created — the basis of data privacy and factories.

function counter() {
  let n = 0;
  return () => ++n;
}
const next = counter();
console.log(next(), next(), next());

2 Asynchronous JavaScript

Promises represent future values; async/await reads asynchronous code like synchronous code. Use try/catch for errors.

function delay(v) {
  return new Promise(res => setTimeout(() => res(v), 50));
}
async function run() {
  const x = await delay('done');
  console.log(x);
}
run();

3 Modules & pure functions

ES modules use export/import. Prefer small, pure functions (no side effects) — they are easier to test and reuse.

// pure: same input -> same output
const slugify = (s) => s.toLowerCase().trim().replace(/\s+/g, '-');
console.log(slugify('  Hello World  '));

⚡ JavaScript Compiler

Code runs live in a sandboxed frame, rendered by your browser.

JS

            

📝 Tasks

5 tasks across 2 pages — multiple-choice and fill-in (type the answer). Score 70% or higher to earn your certificate.

🎓 Certificate of Completion

🔒 Pass the quiz above (70%+) to unlock your downloadable certificate.