DEV Community

Deep Bag
Deep Bag

Posted on • Updated on


Enter fullscreen mode Exit fullscreen mode

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) {
  } else {

    then(function () {
        console.log('Success, You are a GEEK');
    catch(function () {
        console.log('Some error has occurred');
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

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.

5. What is higher order function?
A higher order function is a function that takes a function as an argument, or returns a function.
The map function is one of the many higher-order functions built into the language. sort, reduce, filter, forEach are other examples of higher-order functions built into the language.

Top comments (0)