• Post author:
  • Post category:Blog
  • Reading time:2 mins read
  • Post last modified:June 12, 2024

You have defined a function using the following function expression:

let sum = function (a, b) {
    return (a + b);
}

What could the definition of the corresponding arrow function look like?

  • let sum = (a, b) => {
       a + b;
    };
  • let sum = function (a, b) => {
        return (a + b);
    }
    ;
  • let sum = (a, b) > a + b;
  • let sum = (a, b) => a + b;
  • Explanation & Hint:

    The corresponding arrow function definition for the given function expression would look like: let sum = (a, b) => a + b;

    In arrow functions, the syntax is more concise compared to regular function expressions. The arrow function uses the => (arrow) operator, which separates the function parameters from the function body. In this case, the arrow function takes the parameters a and b and returns their sum without explicitly using the return keyword. The result is obtained by simply expressing the addition as a + b.

    The arrow function preserves the functionality of the original function expression sum but provides a more concise and expressive syntax.

For more Questions and Answers:

JavaScript Essentials 1 | JSE1 – Module 5 Test Exam Answers Full Score 100%

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments