100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
HomeBlogJavaScript Promises and Async/Await Explained
Programming

JavaScript Promises and Async/Await Explained

SV

SkillVeris Team

Engineering Team

Dec 20, 2025 8 min read
Share:
JavaScript Promises and Async/Await Explained
Key Takeaway

A JavaScript Promise is an object representing the eventual result of an asynchronous operation, ending in one of three states: pending, fulfilled, or rejected.

In this guide, you'll learn:

  • You handle a Promise with .then for success and .catch for errors, or more cleanly with async/await syntax.
  • async/await is syntactic sugar over Promises — await pauses a function until a Promise settles, making async code read like ordinary sequential code.
  • Wrap await calls in try/catch to handle rejected Promises the same way you handle thrown errors.
  • Promise.all runs multiple Promises concurrently and resolves when all succeed, which is faster than awaiting them one by one.

1What Is a JavaScript Promise?

A JavaScript Promise is an object that represents a value that is not available yet but will be at some point — the result of an asynchronous operation like a network request or a timer. A Promise is always in one of three states: pending while the work is ongoing, fulfilled when it succeeds with a value, or rejected when it fails with an error.

Promises exist because JavaScript is single-threaded. Rather than freeze the page while waiting for slow work, a Promise lets you register callbacks that run later, once the result settles, keeping the interface responsive.

2Handling Promises With then and catch

The traditional way to consume a Promise is with .then and .catch. The function passed to .then receives the fulfilled value; the one passed to .catch receives the rejection reason. Because .then returns a new Promise, you can chain steps together, each handing its result to the next.

  • fetch('/api/user')
  • .then(response => response.json()) // returns another Promise
  • .then(user => console.log(user.name)) // runs after json resolves
  • .catch(error => console.error(error)) // catches any step failing
  • .finally(() => console.log('done')) // always runs

💡Chaining Rule

Return the Promise inside a .then callback so the next .then waits for it. Forgetting the return is the most common source of chains that run out of order.

3Cleaner Code With async/await

async/await is modern syntax layered on top of Promises. Mark a function async and you can use await inside it to pause until a Promise settles, then continue with its resolved value as if it were returned synchronously. The code reads top to bottom, which is far easier to follow than nested .then chains.

Under the hood nothing changes — await simply waits for the same Promise. It is a readability upgrade, not a new mechanism.

  • async function loadUser() {
  • const response = await fetch('/api/user'); // waits here
  • const user = await response.json(); // then waits here
  • return user.name; // resolves the returned Promise
  • }

4Handling Errors With try/catch

With async/await, a rejected Promise behaves like a thrown error, so you catch it with a normal try/catch block. This unifies error handling: synchronous exceptions and async failures are caught the same way, which is one of the biggest ergonomic wins over .catch chains.

  • async function loadUser() {
  • try {
  • const response = await fetch('/api/user');
  • if (!response.ok) throw new Error('Request failed');
  • return await response.json();
  • } catch (error) {
  • console.error('Could not load user:', error);
  • }
  • }

⚠️fetch Does Not Reject on 404

The fetch Promise only rejects on network failure, not on HTTP error status codes. Always check response.ok yourself and throw if it is false, or bad responses slip through silently.

5Running Promises Concurrently

Awaiting Promises one after another makes them run in sequence, which wastes time when they are independent. Promise.all launches them together and resolves once all have fulfilled, collapsing the total wait to that of the slowest one. Related helpers cover other patterns.

  • const [user, posts] = await Promise.all([fetchUser(), fetchPosts()]); // concurrent
  • Promise.allSettled([...]) // waits for all, never short-circuits on rejection
  • Promise.race([...]) // resolves or rejects with the first to settle
  • Promise.any([...]) // resolves with the first fulfilled, ignoring rejections

Sequential vs Concurrent

Two requests that each take one second run in two seconds when awaited in a row, but about one second inside Promise.all. Use Promise.all whenever the operations do not depend on one another.

6Async Functions Always Return Promises

Every async function returns a Promise, no matter what you write inside it. If you return a plain value, it is wrapped in a resolved Promise; if you throw, the Promise rejects. This means the caller of an async function must await it or attach .then — you cannot use the return value directly as if it were synchronous.

  • async function getNumber() { return 42; } // returns Promise<number>
  • const n = getNumber(); // n is a Promise, not 42
  • const value = await getNumber(); // value is 42
  • getNumber().then(v => console.log(v)); // also works

7Best Practices

A few habits keep async JavaScript predictable and free of the subtle bugs that come from unhandled rejections or accidental serial execution.

  • Always handle rejections — with try/catch around await, or a .catch on the chain.
  • Use Promise.all for independent operations instead of awaiting them one by one.
  • Check response.ok after fetch; it does not reject on HTTP error codes.
  • Avoid await inside a plain forEach loop — it does not wait; use a for...of loop.
  • Do not mix .then chains and await in the same function; pick one style for clarity.

8Key Takeaways

The essentials of Promises and async/await come down to these points.

  • A Promise represents a future value and settles as fulfilled or rejected.
  • async/await is cleaner syntax over Promises that reads sequentially.
  • Handle async errors with try/catch around your await calls.
  • Run independent Promises concurrently with Promise.all to save time.
  • Every async function returns a Promise, so its result must be awaited or handled.

9Frequently Asked Questions

Q: What is the difference between a Promise and async/await? A: They are two ways to work with the same thing. A Promise is the underlying object representing a future value, handled with .then and .catch. async/await is syntax that lets you consume Promises in code that reads top to bottom, but it produces and awaits the very same Promises.

Q: Does await block the whole page? A: No. await only pauses the async function it sits in; the rest of your program, including the UI, keeps running. That is the point of asynchronous code — the single JavaScript thread stays free to handle other work while the awaited operation completes.

Q: Why is my async function returning a Promise instead of a value? A: Because async functions always wrap their return value in a Promise. To get the underlying value, await the function call inside another async function, or attach a .then handler. You cannot read the value synchronously.

Q: When should I use Promise.all? A: Use Promise.all when you have several independent asynchronous operations and want them to run concurrently rather than one after another. It resolves once all have fulfilled and rejects immediately if any one fails, so use Promise.allSettled if you need every result regardless of failures.

📄

Get The Print Version

Download a PDF of this article for offline reading.

About the Publisher

SV

SkillVeris Team

Engineering Team

Our engineering writers turn abstract code concepts into hands-on, project-driven learning experiences.

View all posts

Never miss an update

Get the latest tutorials and guides delivered to your inbox.

No spam. Unsubscribe anytime.

Frequently Asked Questions

21 categories · pick one to explore

Does SkillVeris have a tech blog, and what does it cover?
Yes, the SkillVeris blog has over 500 articles covering AI and machine learning, programming, web development, DevOps, cloud, security, databases and career guidance. Articles are practical and answer-first, and many use the Learn Through Hobbies approach, teaching technical concepts through cricket, music, gaming or cooking analogies. Everything is free to read.
What is the SkillVeris tech glossary and how big is it?
The SkillVeris glossary is a free reference of roughly 2,000-plus technology terms, each with a clear plain-language definition. It spans AI, programming, web, DevOps, cloud, security and database vocabulary, so whenever a lesson, article or job description uses jargon you do not recognise, the glossary gives you a fast, reliable answer.
Are the developer cheat sheets on SkillVeris free to download?
The cheat sheets are completely free to use, like everything else on SkillVeris. Each sheet condenses a language or tool into its essential syntax, commands and patterns for quick reference while coding. They are designed for rapid lookup during real work, complementing the deeper explanations found in study notes and courses.
Which programming references and cheat sheets are available?
Cheat sheets cover the platform's main domains, including programming languages, AI and ML tooling, web development, DevOps, cloud, security and databases, matching the topics of the 37 live courses. Each sheet lists related reading links and hashtags, so you can jump from a quick reference into fuller study notes or blog articles.
How do I find the meaning of a technical term quickly?
Search the SkillVeris glossary, which holds around 2,000-plus terms with concise, plain-language definitions. Each entry gets to the point in its first sentence, then links to related reading like blog posts or study notes for deeper context. It is faster and more consistent than sifting through scattered search results.
Is the SkillVeris blog good for beginners learning to code?
Yes, many blog articles are written specifically for beginners, and the Learn Through Hobbies style makes them unusually approachable: you might learn Python concepts through cricket or understand APIs through cooking. With 500-plus articles across skill levels, beginners can start with fundamentals and keep reading as they advance, entirely free.
Can cheat sheets replace full courses for learning a language?
No, cheat sheets are references, not teaching tools; they assume you already understand the concepts and just need syntax or commands fast. To actually learn a language, take a structured SkillVeris course with its 24–40 lessons and assessments, then keep the cheat sheet beside you while practising in Code Lab.
How often are new blog articles published on SkillVeris?
The blog grows regularly and already exceeds 500 articles, with new posts added as courses launch and technologies evolve. Topics track the platform's catalogue across AI, programming, web development, DevOps, cloud and security, so checking the Blog section periodically surfaces fresh tutorials, explainers and career-focused pieces, all free to read.
Does the glossary cover AI and machine learning terms?
Yes, AI and machine learning vocabulary is a major part of the roughly 2,000-plus term glossary, covering everything from foundational terms to modern concepts around LLMs, RAG and MLOps. Definitions are plain-language and answer-first, which helps when dense AI papers or course lessons throw unfamiliar jargon at you.
Are there cheat sheets for interview preparation?
Cheat sheets work well as interview-day refreshers because they compress syntax, commands and key concepts into scannable references. For dedicated preparation, combine them with the SkillVeris interview questions feature, which includes readiness scoring, plus study notes for depth. Reviewing a relevant cheat sheet just before an interview steadies recall under pressure.
Can I read the tech blog without signing up?
Yes, the blog is freely readable, and SkillVeris never charges for content. All 500-plus articles are open, covering tutorials, concept explainers and career advice. Creating a free account adds value elsewhere on the platform, like course progress tracking and certificates, but reading the blog requires no commitment at all.
How is the SkillVeris glossary different from Wikipedia?
The glossary is purpose-built for learners: definitions are short, plain-language and answer-first, sized for a quick lookup mid-lesson rather than a deep encyclopedic read. Entries also cross-link to related SkillVeris study notes, blog posts and courses, so a definition becomes a doorway into structured learning instead of a dead end.
Do blog articles use the Learn Through Hobbies method?
Many blog articles teach technical topics through hobby analogies, a hallmark of the SkillVeris blog, so you will find articles explaining programming through cricket, machine learning through music, or system design through cooking. The analogy is the teaching device; the article still delivers the real technical concept underneath.
Where can I find quick programming references while coding?
Open the SkillVeris cheat sheets, which are built exactly for that moment: compact, scannable references for syntax, commands and common patterns across languages and tools. Keep the relevant sheet in a browser tab while you work in Code Lab or your own editor, and dip into the glossary for terminology.
Is there a glossary entry for terms I meet in job descriptions?
Very likely yes, with roughly 2,000-plus terms across AI, programming, web, DevOps, cloud, security and databases, the glossary covers most jargon that appears in tech job descriptions. Decoding a listing this way helps you judge role fit honestly and prepares you to discuss those terms in interviews.
Are the blog articles written for the Indian tech audience?
The blog serves Indian learners plus a worldwide audience. Content stays globally relevant while acknowledging realities that matter in India, such as free access being essential for students and freshers, and career guidance that connects naturally to the SkillVeris jobs portal, which aggregates roles across India, UK, USA, Germany and Remote.
Can I suggest a topic for the blog or glossary?
SkillVeris content grows in response to what learners need, so feedback is welcome through the platform's support channels. If a term is missing from the glossary or a topic deserves an article, telling the team helps prioritise it. Meanwhile, the AI Mentor can answer the question immediately, 24/7, at any depth.
Do cheat sheets and glossary entries link to deeper learning?
Yes, every cheat sheet and glossary entry carries related reading links into study notes, blog articles and courses, plus concept hashtags for discovering similar content. This cross-linking means a thirty-second lookup can smoothly become a structured learning session whenever you decide you want more than a quick answer.
What makes SkillVeris programming references trustworthy?
The references are written to strict internal quality standards, kept consistent with the platform's 37 live courses, and never padded with invented statistics or hype. Definitions and cheat sheets are reviewed against the same content contracts that govern courses, and the answer-first style makes any inaccuracy easy to spot and correct.
How do the blog, glossary and cheat sheets fit into my learning routine?
Use them as satellites around your main course: read blog articles for context and motivation, hit the glossary the instant jargon appears, and keep cheat sheets open while coding. Together with study notes, Code Lab and the 24/7 AI Mentor, they turn passive reading into a complete, free learning system.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse