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

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'); }; }

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 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 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'); } };

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!'))

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

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 correctly demonstrates a function returning another function?

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'); }; }

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