> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript Async Method

An asynchronous method in JavaScript is a function declared with the `async` keyword that operates asynchronously via the event loop. It guarantees that the function's return value is always a newly allocated `Promise` object. If the function returns a non-Promise value, the JavaScript engine implicitly wraps it in a resolved `Promise`. If the function throws an exception, it returns a rejected `Promise`. Crucially, if the function returns an existing `Promise`, the `async` function does not return it as-is; instead, it returns a new `Promise` that adopts the state (fulfillment or rejection) of the returned `Promise`, meaning the returned object reference is always distinct.

A primary technical utility of an `async` method is establishing an execution context where the `await` operator can be utilized. (Note: As of ES2022, Top-Level `await` allows the `await` keyword to be used entirely outside of `async` functions at the top level of ES modules).

The `await` keyword pauses the execution of the `async` function until its operand settles (either fulfills or rejects). This operand does not strictly need to be a `Promise`; `await` accepts non-Promise values (e.g., `await 42`), which the engine implicitly treats as a resolved `Promise`. During the pause, control is yielded back to the calling execution context, preventing the main thread from blocking. Once the awaited operand settles, the continuation of the `async` function is scheduled on the microtask queue.

## Syntax Variations

The `async` modifier can be applied to various function definitions, including declarations, expressions, arrow functions, and class/object methods:

```javascript theme={"dark"}
// Function Declaration
async function asyncDeclaration() {
  return 1;
}

// Function Expression
const asyncExpression = async function() {
  return 2;
};

// Arrow Function
const asyncArrow = async () => {
  return 3;
};

// Object Method
const obj = {
  async asyncMethod() {
    return 4;
  }
};

// Class Method
class MyClass {
  async asyncClassMethod() {
    return 5;
  }
}
```

## Return Value Mechanics

Because an `async` method strictly returns a newly allocated `Promise`, standard return statements and thrown errors are automatically transformed by the engine:

```javascript theme={"dark"}
async function returnPrimitive() {
  return "string"; 
  // Engine transforms to a new Promise resolved with "string"
}

async function throwError() {
  throw new Error("fail"); 
  // Engine transforms to a new Promise rejected with the Error
}

async function returnPromise() {
  const p = Promise.resolve("existing promise");
  return p; 
  // Returns a NEW Promise that adopts the state of 'p'.
  // The expression (returnPromise() === p) evaluates to false.
}
```

## Execution Flow and `await`

When `await` is used within an `async` method, it unwraps the resolved value of the operand. If the awaited operand is a rejected `Promise`, the `await` expression throws the rejection reason as an exception, which can be intercepted using standard synchronous `try...catch` blocks.

```javascript theme={"dark"}
async function executionFlow() {
  try {
    // Execution context pauses here until the Promise fulfills
    const result = await Promise.resolve(10);
    
    // Awaits a non-Promise value; implicitly treated as Promise.resolve(2)
    const multiplier = await 2;
    
    // The following code executes in a new microtask
    const mathematicalOperation = result * multiplier; 
    
    // Awaited rejections are thrown as synchronous exceptions
    await Promise.reject(new Error("Rejection reason"));
    
    // This line is unreachable due to the thrown error above
    return mathematicalOperation; 
  } catch (error) {
    // Catches the rejected Promise from the await expression
    return error.message; 
  }
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor JavaScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
