Javascript Developer JSE 40 01 · Free Practice Question Medium
Question 27
Q543 - Functions
You have defined the following arrow function:
- let multiply = (m, n) => m * n;
Select the correct regular declarations
of the corresponding function or function expression.
(Select two correct answers)
-
A
- function multiply(m, n) { m = m * n; }
-
B
- function multiply(m, n) { m * n; }
-
C
- function multiply(m, n) { return m * n; }
-
D
- let multiply = function (m, n) { return m * n; }
Reveal correct answers
Correct answers: C, D
Explanation
Topics: function declaration function expression
Try it yourself:
- let multiply = (m, n) => m * n;
- console.log(multiply(3, 4)); // 12
- function multiply1(m, n) { return m * n; }
- console.log(multiply1(3, 4)); // 12
- let multiply2 = function (m, n) { return m * n; }
- console.log(multiply2(3, 4)); // 12
- function multiply3(m, n) { m * n; }
- console.log(multiply3(3, 4)); // undefined
- function multiply4(m, n) { m = m * n; }
- console.log(multiply4(3, 4)); // undefined
Explanation:
Only two of the functions return the value.
The function declaration (function statement) defines a function.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function
Function expression
The function keyword can be used to define a function inside an expression.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function
(There is a similar question Q329.)
Q543 (Please refer to this number, if you want to write me about this question.)
A. This choice is incorrect because it assigns the product of m and n to m within the function, which is not the same behavior as the arrow function that calculates and returns the product.
B. This choice is incorrect because it lacks a return statement, so the function does not return the product of m and n as intended.
C. This choice correctly represents the arrow function as a regular function declaration with the function keyword, parameter list, and return statement that calculates the product of m and n.
D. This choice correctly represents the arrow function as a regular function expression using the let keyword to declare the function and the function keyword with a parameter list and a return statement that calculates the product of m and n.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
