DEV Community

Cover image for a/synchronous code.
Maggie DeSantis
Maggie DeSantis

Posted on

1

a/synchronous code.

Couldn't think of a clever title for this one. Instead I'll just share what I'm doing for the next 2 hours for bootcamp and #100DaysOfCode.

SD Phase 1 - Full Stack - Asynchronous JavaScript | Post - Patch and Delete Requests.

Mimo web-development training - CSS intermediate

Synchronous Code:
is executed sequentially, line by line, in the order it appears in the code. Each task must complete before the next one begins, and the code waits for each task to finish before moving on to the next. This can lead to blocking or freezing the user interface

console.log('Start');
console.log('Fetching data...');

// Fetch data synchronously
const data = fetchDataSync(); // This fetch operation blocks the code execution

console.log('Data fetched:', data);
console.log('End');

Enter fullscreen mode Exit fullscreen mode

Asynchronous Code:
allows multiple tasks to be executed concurrently without blocking the execution of other tasks. This helps to keep the application responsive and prevents it from freezing while time-consuming tasks, such as data fetching, are being performed

console.log('Start');
console.log('Fetching data...');

// Fetch data asynchronously with a callback
fetchDataAsync((error, data) => {
  if (error) {
    console.error('Error fetching data:', error);
  } else {
    console.log('Data fetched:', data);
  }
});

console.log('End');
Enter fullscreen mode Exit fullscreen mode

5/100

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay