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.