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 can you define a method inside an object?

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

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

C). Both A and B

D). var obj = { function method() { 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 output of the following code? var person = { name: 'Alice', greet: function() { return 'Hello, ' + this.name; } }; console.log(person.greet());

A). Hello, Alice

B). Hello, undefined

C). Hello, name

D). undefined

What will be the output of the following code? var counter = (function() { var count = 0; return function() { return ++count; }; })(); console.log(counter()); console.log(counter());

A). 1, 2

B). 0, 1

C). undefined, undefined

D). 2, 4

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

What will be the output of the following code? var sayHi = function() { return 'Hi'; }; console.log(sayHi());

A). Hi

B). undefined

C). sayHi

D). function

How do you define an anonymous function assigned to a variable?

A). var anon = function() { alert('Anonymous!'); };

B). var anon = function { alert('Anonymous!'); };

C). function anon() { alert('Anonymous!'); }

D). var anon = function anonymous() { alert('Anonymous!'); };

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

How do you define a function using a function expression?

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

B). function myFunc() { alert('Hello'); }

C). var myFunc = function { alert('Hello'); };

D). var myFunc() { alert('Hello'); }

What will be the output of the following code? var add = new Function('a', 'b', 'return a + b'); console.log(add(2, 3));

A). 5

B). add

C). undefined

D). 2 3