Open In App
Related Articles

JavaScript return Statement

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

JavaScript return statement is used to return a particular value from the function. The function will stop the execution when the return statement is called and return a specific value. The return statement should be the last statement of the function because the code after the return statement won’t be accessible.

We can return any value i.e. Primitive value (Boolean, number and string, etc) or object type value ( function, object, array, etc) by using the return statement.

Syntax:

return value;

 Where:

  • value: The value returned to the function caller. It is an optional parameter. If the value is not specified, the function returns undefined

Example 1: In this example, we are returning the multiplication value of the given parameters.

Javascript

function Product(a, b) {
    // Return the product of a and b
    return a * b;
};
console.log(Product(6, 10));

                    

Output
60

Example 2: In this example, we will return multiple values by using the object and we are using ES6 object destructuring to unpack the value of the object.

Javascript

function Language() {
    let first = 'HTML',
        second = 'CSS',
        Third = 'Javascript'
    return {
        first,
        second,
        Third
    };
}
let { first, second, Third } = Language();
console.log(first);
console.log(second);
console.log(Third);

                    

Output
HTML
CSS
Javascript


Last Updated : 07 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads