MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Intro to Async/Await0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
7.1Callbacks7.2Promises Basics7.3Promise Chaining7.4Intro to Async/Await
HomeTutorialsJavaScript for IntermediateIntro to Async/Await
Fetching Data from APIs

Intro to Async/Await

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Introduced in ECMAScript 2017 (ES8), async and await are syntactic sugar built on top of JavaScript Promises. They allow you to write asynchronous code that reads and behaves like synchronous code, eliminating nested .then() callbacks and enabling standard try...catch blocks.


1. The async Keyword

Placing async before a function declaration or arrow function does two things:

  1. 1
    It permits the use of await inside that function.
  2. 2
    It always returns a Promise, automatically wrapping non-promise return values.
1async function getGreeting() {
2 return 'Hello, World!'; // Automatically wrapped in Promise.resolve()
3}
4 
5// Consuming the async function
6getGreeting().then(msg => console.log(msg)); // 'Hello, World!'

2. The await Keyword

await can only be used inside async functions (or at the top level of modern ES modules). It pauses execution of the async function until the Promise settles:

1function delay(ms) {
2 return new Promise(resolve => setTimeout(resolve, ms));
3}
4 
5async function runDemo() {
6 console.log('Step 1: Beginning operation...');
7
8 await delay(1000); // Pauses runDemo execution for 1000ms
9
10 console.log('Step 2: Resumed after 1 second!');
11}
12 
13runDemo();
Crucial Concept: await does not block the entire browser or main JavaScript thread! It only pauses the execution frame of that specific async function, allowing other events and UI updates to proceed.

3. Comparing Promise Chaining vs. Async/Await

With Promise Chaining (.then/.catch):

1function loadDashboard(userId) {
2 return fetchUserData(userId)
3 .then(user => fetchUserFeed(user.feedId))
4 .then(feed => renderFeed(feed))
5 .catch(err => showError(err));
6}

With Modern Async/Await:

1async function loadDashboard(userId) {
2 try {
3 const user = await fetchUserData(userId);
4 const feed = await fetchUserFeed(user.feedId);
5 renderFeed(feed);
6 } catch (err) {
7 showError(err);
8 }
9}

4. Sequential vs. Parallel Execution Pitfall

A common beginner mistake is awaiting independent asynchronous tasks sequentially, leading to unnecessary delays:

1// SLOW (Sequential): Takes 1000ms + 1000ms = 2000ms
2async function loadSlow() {
3 const profile = await fetchProfile(); // Takes 1s
4 const analytics = await fetchAnalytics(); // Takes 1s
5 return { profile, analytics };
6}
7 
8// FAST (Concurrent): Takes max(1000ms, 1000ms) = 1000ms!
9async function loadFast() {
10 // Fire both promises simultaneously
11 const profilePromise = fetchProfile();
12 const analyticsPromise = fetchAnalytics();
13 
14 // Await both together
15 const [profile, analytics] = await Promise.all([profilePromise, analyticsPromise]);
16 return { profile, analytics };
17}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does an async function always return?
Question 2
What happens if you use the await keyword inside a standard synchronous function?
Question 3
Does await freeze the entire browser window while waiting for a network request?
Question 4
How is error handling typically implemented in async/await functions?
Question 5
How should two independent network requests be awaited to minimize latency?
Next Lesson

Fetching Data from APIs

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Promise ChainingFetching Data from APIs

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext