Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 24, 2022 12:22 pm GMT

JAVASCRIPT IMPORTANT THINGS THAT YOU WANT TO KNOW!

**

https://www.freecodecamp.org/news/async-await-in-javascript/

**
1. What is Async/Await?
Async/Await makes it easier to write promises. The keyword 'async' before a function makes the function return a promise, always. And the keyword await is used inside async functions, which makes the program wait until the Promise resolves.

2. What is promises?
Promises are used to handle asynchronous operations in JavaScript.
In another words:
A promise is a value that may produce a value in the future. That value can either be resolved or unresolved (in some error cases, like a network failure). It works like a real-life promise.

_Benefits of Promises _

  • Improves Code Readability
  • Better handling of asynchronous operations
  • Better flow of control definition in asynchronous logic
  • Better Error Handling

_A Promise has four states: _

  1. fulfilled: Action related to the promise succeeded
  2. rejected: Action related to the promise failed
  3. pending: Promise is still pending i.e. not fulfilled or rejected yet
  4. settled: Promise has fulfilled or rejected
var promise = new Promise(function(resolve, reject) {  const x = "DEEPBAG";  const y = "DEEPBAG"  if(x === y) {    resolve();  } else {    reject();  }});promise.    then(function () {        console.log('Success, You are a GEEK');    }).    catch(function () {        console.log('Some error has occurred');    });

3. What is Callback Functions?
A callback is a function passed as an argument to another function. This technique allows a function to call another function
In another words:
Callback functions are those functions that have been passed to another function as an argument.

function myDisplayer(some) {  document.getElementById("demo").innerHTML = some;}function myCalculator(num1, num2) {  let sum = num1 + num2;  return sum;}let result = myCalculator(5, 5);myDisplayer(result);

4. What is Synchronous and Asynchronous?
Synchronous communications are scheduled, real-time interactions by phone, video, or in-person.
Asynchronous communication happens on your own time and doesn't need scheduling.


Original Link: https://dev.to/erdeepbag/javascript-important-things-that-you-want-to-know-4nk6

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To