Q
Which statement correctly defines a function named sum that returns the sum of two parameters a and b?

Answer & Solution

Answer: Option A
Solution:
The correct syntax is function sum(a, b) { return a + b; }.
Related Questions on Average

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

A). Global

B). Local to the function

C). Local to the script

D). It depends on the variable type

How do you define a function that takes parameters?

A). function myFunction[] { }

B). function myFunction(parameters) { }

C). function myFunction{parameters}

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

Which of the following is an example of an arrow function?

A). function => { }

B). () => { }

C). arrow function() { }

D). => function() { }

What is a method in JavaScript?

A). A function stored as a property of an object

B). A variable declared within a function

C). A keyword used to define a function

D). A loop within a function

How do you call a method named greet that belongs to an object person?

A). person(greet);

B). person.greet();

C). greet.person();

D). call person.greet();

Which of the following is true about functions in JavaScript?

A). Functions cannot be nested

B). Functions can only have one parameter

C). Functions can be assigned to variables

D). Functions cannot return values

What is the purpose of the return statement in a function?

A). To output a value to the console

B). To exit a function and return a value

C). To pass a value to another function

D). To loop through a function

Which keyword is used to declare a function in JavaScript?

A). func

B). function

C). def

D). declare

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

A). undefined

B). test

C). Hello

D). error

How can you assign a function to a variable?

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

B). var myFunc = function { };

C). var myFunc function() { };

D). var function myFunc() { };