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
Promises Basics0%
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 IntermediatePromises Basics
Promise Chaining

Promises Basics

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

A Promise is an object representing the eventual completion (or failure) of an asynchronous operation and its resulting value. Introduced in ES6, Promises provide a structured, standardized abstraction over asynchronous programming, replacing error-prone nested callbacks.


1. The Three States of a Promise

A Promise exists in one of three mutually exclusive states:

1 ┌───────────────┐
2 │ PENDING │ (Initial state, operation in progress)
3 └───────┬───────┘
4 │
5 ┌───────────────┴───────────────┐
6 │ │
7 ▼ ▼
8 ┌───────────────┐ ┌───────────────┐
9 │ FULFILLED │ │ REJECTED │
10 │ (Success) │ │ (Failure) │
11 └───────────────┘ └───────────────┘
  1. 1
    Pending: Initial state; the asynchronous operation is still running.
  2. 2
    Fulfilled (Resolved): The operation completed successfully with a resulting value.
  3. 3
    Rejected: The operation failed with a reason or error object.
Immutability Guarantee: Once a Promise transitions to Fulfilled or Rejected (termed settled), its state and value can never change again.

2. Creating a Promise: The Promise Constructor

The Promise constructor accepts an executor function with two arguments: resolve and reject.

1function fetchServerStatus(isHealthy) {
2 return new Promise((resolve, reject) => {
3 console.log('Initiating server health check...');
4 
5 setTimeout(() => {
6 if (isHealthy) {
7 resolve({ status: 200, uptime: '99.99%', message: 'System Operational' });
8 } else {
9 reject(new Error('503 Service Unavailable: Database unreachable'));
10 }
11 }, 1500);
12 });
13}

3. Consuming Promises: .then(), .catch(), and .finally()

To handle the outcome of a Promise, use handler methods:

1fetchServerStatus(true)
2 .then((data) => {
3 // Executes ONLY if fulfilled
4 console.log('Health Check Passed:', data.message);
5 return data.status;
6 })
7 .catch((error) => {
8 // Executes if rejected OR if an error was thrown in .then()
9 console.error('Health Check Failed:', error.message);
10 })
11 .finally(() => {
12 // Executes in ALL cases (settled)
13 console.log('Health check cycle completed.');
14 });

4. Static Helper Methods: Promise.resolve() & Promise.reject()

Quickly instantiate already-settled promises:

1// Returns a Promise fulfilled immediately with 42
2const instantSuccess = Promise.resolve(42);
3 
4// Returns a Promise rejected immediately with an Error
5const instantFailure = Promise.reject(new Error('Unauthorized access'));

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Which of the following is NOT a valid state of a JavaScript Promise?
Question 2
What happens once a Promise reaches either the Fulfilled or Rejected state?
Question 3
What method is guaranteed to run when a Promise finishes, regardless of whether it was fulfilled or rejected?
Question 4
How does a Promise handle uncaught exceptions thrown inside its executor function?
Question 5
What does Promise.resolve('Hello') return?
Next Lesson

Promise Chaining

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

Related Lessons

Previous LessonNext Lesson
CallbacksPromise Chaining

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