Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Synchronous, Asynchronous, and Promise in Javascript

1. Synchronous JavaScript Synchronous means code executes one line at a time, in order. The next line waits until the current line finishes. Example: console . log ( " First " ); console . log ( " Second " ); console . log ( " Third " ); Output : First Second Third Explanation: First line executes. Then the second line executes. Finally, the third line executes. Each statement runs in sequence.…

Synchronous JavaScript operates line by line, executing each instruction in order. The subsequent line waits until the current one concludes. For instance, console.log("First"); console.log("Second"); console.log("Third"); produces First Second Third. Each statement runs sequentially, with no overlap.

Asynchronous JavaScript permits operations to commence and conclude at varied intervals, enabling other code to execute concurrently. console.log("First"); setTimeout(function() { console.log("Second"); }, 2000); console.log("Third"); outputs First Third Second. "First" prints instantaneously. "setTimeout()" schedules the callback to execute after a minimum of 2 seconds. "Third" prints without waiting for the timer. "Second" prints once the timer callback runs.

A Promise embodies the eventual outcome of an asynchronous operation – success or failure. It exists in three states: Pending (operation incomplete), Fulfilled (success), or Rejected (failure). let myPromise = new Promise((resolve, reject) => { resolve("Task completed!"); }); myPromise.then(result => { console.log(result); }); Outputs Task completed!.

Here's a rejected Promise: let myPromise = new Promise((resolve, reject) => { reject("Something went wrong"); }); myPromise.catch(error => { console.log(error); }); Outputs Something went wrong.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

ListingForge

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle ListingForge ⚡ — The Open-Weight AI E-Commerce Listing Studio What I Built ListingForge is a local-first…

  • ListingForge AI studio converts raw images into optimized listings for major platforms.
  • Users create high-converting listings in under 30 seconds with built-in presets.
  • Platform offers subscription or lifetime license with zero marginal costs.

Audit contests: $451 of prize money per submission in 2024, $85 in 2026

Disclosure: the data collection, the analysis, the code and this post were made with AI agents working for me, MV2 of Munim, Inc. Every number below comes from an open dataset you can re-run yourself…

  • Prize money per submission dropped to $85 in 2026
  • Total prize money rose to $1.56 million in 2026
  • Only 22% of 97 audits paid out any prize money

More from Thursday, 15 October 2026 →