Search...

⌘K

Stories

Scores

Talent

Narrative detail line items

Why our story suggestions matter

Why tell stories?

What if my resume bullet isn’t accurate?

Resume bullet points

Direct + transferable skills

Story requirements

Understanding your fit score

How we handle your facts

Getting Started

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Getting Started

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Getting Started

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Label

Stories

Scores

Talent

What are narrative detail line items

Why our story suggestions matter

Why tell stories?

What if my resume bullet isn’t accurate?

Careerspan resume bullet points

Direct + transferable skills

Why story requirements give hiring managers the data they actually need

Understanding your fit score: What each number really means

How we handle your facts

Callbacks

A callback is a function passed as an argument to another function, which is then executed after the completion of an operation.

Example of a Callback Function

function fetchData(callback) {
  setTimeout(() => {
    console.log("Data fetched");
    callback();
  }, 2000);
}
  
function processData() {
  console.log("Processing data...");
}
  
fetchData(processData);

fetchData simulates an asynchronous operation using setTimeout.

processData is executed after fetchData completes.

Promises

A promise represents a future value and has three states:

  1. Pending – Initial state, operation in progress.

  2. Fulfilled – Operation completed successfully.

  3. Rejected – Operation failed.

Creating a Promise

let fetchData = new Promise((resolve, reject) => {
  setTimeout(() => {
    let success = true; // Change to false to test rejection
    if (success) {
      resolve("Data received");
        } else {
      reject("Error fetching data");
    }
  }, 2000);
});
  
fetchData
  .then(result => console.log(result)) // Executes if resolved
  .catch(error => console.log(error)) // Executes if rejected
.finally(() => console.log("Operation complete"));

.then() runs when the promise is resolved.

.catch() runs when the promise is rejected.

.finally() runs regardless of success or failure.

Conclusion

Asynchronous programming allows JavaScript to handle time-consuming operations efficiently. Callbacks, promises, and async/await help manage asynchronous workflows. The next section will explore DOM manipulation, which enables JavaScript to interact with web pages dynamically.

Advanced

Table of Content

Table of Content

Table of Content

Asynchronous JavaScript

JavaScript is single-threaded, meaning it executes one operation at a time. However, asynchronous programming allows JavaScript to handle time-consuming tasks (e.g., fetching data, reading files) without blocking the main execution thread.

Get Template for free

Get Template for free

Get Template for free