Q
What is the correct way to return an object from a function?

Answer & Solution

Answer: Option B
Solution:
To return an object, use return { };.
Related Questions on Average

What will be the output of the following code: function test() { return 'Hello'; } console.log(test());?

A). test

B). Hello

C). undefined

D). error

What happens if a function does not have a return statement?

A). It returns undefined

B). It throws an error

C). It returns null

D). It returns 0

What is an anonymous function?

A). A function without a name

B). A function without parameters

C). A function without return value

D). A function without a body

How do you handle the returned value of a function that returns an object?

A). var obj = myFunction(); obj.key;

B). var obj = myFunction().key;

C). var obj = myFunction.key();

D). var obj.key = myFunction();

How do you create a function expression in JavaScript?

A). var myFunction = function() { };

B). var myFunction = function { };

C). var myFunction function() { };

D). var function myFunction() { };

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

A). function anotherFunction(function) { }

B). anotherFunction(function() { });

C). anotherFunction(myFunction);

D). function anotherFunction(myFunction()) { }

How do you immediately invoke a function expression (IIFE)?

A). (function() { })();

B). function() { }();

C). (function() { }());

D). function() { }()

What is the scope of a variable declared within a function?

A). Global

B). Local

C). Block

D). Script

How do you define a default parameter in a function?

A). function myFunction(param = 10) { }

B). function myFunction(param := 10) { }

C). function myFunction(param == 10) { }

D). function myFunction(param : 10) { }

How do you define a function in JavaScript?

A). function myFunction { }

B). function: myFunction() { }

C). function myFunction() { }

D). myFunction function() { }