DEV Community

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

Posted on

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

Top comments (0)