[Solved] Rewrite code from Arrow Function to non arrow function

Introduction

This article will discuss how to rewrite code from an arrow function to a non-arrow function. Arrow functions are a relatively new feature of JavaScript that allow developers to write code in a more concise and expressive way. However, there are certain situations where arrow functions are not supported, and it is necessary to rewrite the code using a non-arrow function. This article will provide an overview of the process of rewriting code from an arrow function to a non-arrow function.

Solution

// Arrow Function
const add = (a, b) => a + b;

// Non Arrow Function
function add(a, b) {
return a + b;
}


require('isomorphic-fetch');

let items = [];

fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699")
  .then(function(res) { return res.json(); })
  .then(function (result) {
    items = result.items;
    console.log(items);
  }),
  function (error) {
    console.log(error);
  }

1

solved Rewrite code from Arrow Function to non arrow function


Rewriting Arrow Functions to Non-Arrow Functions

Arrow functions are a concise way to write functions in JavaScript, but they are not always the best choice. In some cases, it may be necessary to rewrite an arrow function to a non-arrow function. This article will explain how to do this.

What is an Arrow Function?

An arrow function is a shorthand syntax for writing functions in JavaScript. It is a concise way to write functions that are more readable and easier to understand. Arrow functions are also known as “fat arrow” functions because of the “=>” symbol used to define them.

Why Rewrite an Arrow Function?

There are several reasons why you may want to rewrite an arrow function to a non-arrow function. One reason is that arrow functions do not have their own this context, which can be confusing when dealing with objects. Another reason is that arrow functions do not have access to the arguments object, which can be useful when dealing with functions that take multiple arguments. Finally, arrow functions cannot be used as constructors, which can be a limitation when creating objects.

How to Rewrite an Arrow Function

Rewriting an arrow function to a non-arrow function is relatively straightforward. The first step is to replace the “=>” symbol with the keyword “function”. Then, you need to add parentheses around the parameters, if any. Finally, you need to add curly braces around the body of the function.

For example, the following arrow function:

const add = (a, b) => a + b;

Can be rewritten as a non-arrow function like this:

function add(a, b) {
  return a + b;
}

Once you have rewritten the arrow function, you can use it just like any other function.

Conclusion

Arrow functions are a great way to write concise and readable code, but they are not always the best choice. In some cases, it may be necessary to rewrite an arrow function to a non-arrow function. This article has explained how to do this, and provided an example of how to rewrite an arrow function to a non-arrow function.