Q
Which of the following is an example of using a function as a return value?

Answer & Solution

Answer: Option A
Solution:
A function returning another function is correctly demonstrated as function outer() { return function() { alert('Inner'); }; }.
Related Questions on Average

How do you create an Immediately Invoked Function Expression (IIFE)?

A). (function() { alert('IIFE'); })();

B). function() { alert('IIFE'); }();

C). (function { alert('IIFE'); })();

D). function() { alert('IIFE'); };

What will be the output of the following code? var double = function(x) { return x * 2; }; console.log(double(5));

A). 10

B). 5

C). undefined

D). double

How can you pass a function as an argument to another function?

A). performAction(function() { alert('Action!'); });

B). performAction(function { alert('Action!'); });

C). performAction(function() alert('Action!'););

D). performAction(function() alert('Action!'))

How can you invoke a function stored in a variable doSomething?

A). doSomething();

B). call doSomething;

C). doSomething[];

D). invoke(doSomething);

Which of the following is true about functions in JavaScript?

A). Functions can be assigned to variables

B). Functions can be passed as arguments to other functions

C). Functions can be returned from other functions

D). All of the above

How do you assign a function to a variable in JavaScript?

A). var greet = function() { alert('Hello'); };

B). var greet = function { alert('Hello'); };

C). function greet() { alert('Hello'); }

D). var greet = function alert('Hello');

What is the output of the following code? function makeAdder(a) { return function(b) { return a + b; }; } var add5 = makeAdder(5); console.log(add5(2));

A). 7

B). 5

C). add5

D). makeAdder

What is the term for a function that is passed as an argument to another function?

A). Callback function

B). Nested function

C). Helper function

D). Inner function

What will be the output of the following code? var multiply = (x, y) => x * y; console.log(multiply(3, 4));

A). 12

B). 34

C). multiply

D). undefined

How can you store a function as a property of an object?

A). var obj = { method: function() { alert('Hello'); } };

B). var obj = { method: alert('Hello'); };

C). var obj = { method: function { alert('Hello'); } };

D). var obj = { function() { alert('Hello'); } };