Simple return statement

Return statement is used to depict how a function after the completion of its execution can produce some result that can be used further.

Example: Sum of two numbers returned as simple return statement.

Javascript




function sum(firstNumber, secondNumber) {
    return firstNumber + secondNumber;
}
console.log(sum(1, 2))


Output

3

How to use Return in JavaScript ?

JavaScript allows us to use the return statement to end the function’s execution to specify the value that needs to be returned to the code that is calling it. Below are the methods and examples of how to use a return statement in JavaScript.

Syntax:

function nameOfFunction()
{
return result // Value that need to be returned
}

Table of Content

  • Simple return statement
  • Return statement to return different types
  • Return statement for returning objects
  • Return statement to return a function
  • Return statement to exit function prematurely

Similar Reads

Simple return statement

Return statement is used to depict how a function after the completion of its execution can produce some result that can be used further....

Return statement to return different types

...

Return statement for returning objects

Functions in JavaScript are not just limited or bounded to return specific data types, but they can return different data types based on the logic that is defined inside the function....

Return statement to return a function

...

Return statement to exit function prematurely

JavaScript functions also allow us to return the object which helps in hiding the related data and behaviours....

Contact Us