Q
Which of the following is true about functions in JavaScript?

Answer & Solution

Answer: Option D
Solution:
In JavaScript, functions can be assigned to variables, passed as arguments, and returned from other functions.
Related Questions on Average

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

Which of the following is an example of an arrow function assigned to a variable?

A). var add = (a, b) => { return a + b; };

B). var add = (a, b) => return a + b;

C). var add = (a, b) => { a + b };

D). var add = (a, b) { return a + b; };

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

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 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 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 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

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

A). function outer() { return function() { alert('Inner'); }; }

B). function outer() { function() { alert('Inner'); }; return; }

C). function outer() { function() { alert('Inner'); }; }

D). function outer() { return function { alert('Inner'); }; }