Question:

Which of the following statement is used to return a value in a function in JavaScript?

Show Hint

The return statement not only sends a value back but also immediately stops further execution of the function.
  • submit
  • send
  • go
  • return
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: Understand functions in JavaScript.

A function in JavaScript is a block of reusable code that performs a specific task. Functions may accept input values (parameters), process them, and then produce an output. The output of a function is called the return value.

Step 2: Explain the return statement.

The return statement is used to send a value back from a function to the place where the function was called. When the return statement is executed, the function stops running and sends the specified value as the result.

Example:

function add(a, b) {
    return a + b;
}
In this example, the function adds two numbers and returns the result.

Step 3: Analyze other options.

submit: Used mainly in HTML forms to submit data, not in JavaScript functions.

send: Often used in networking or APIs but not used to return values from functions.

go: This is not a valid JavaScript statement for returning values.

Step 4: Conclusion.

Therefore, the correct statement used to return a value from a JavaScript function is the return statement.
Was this answer helpful?
0
0