Q1. What is 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 a return statement is executed, the function immediately stops running and returns the specified value.
Example
When a return statement is executed, the function immediately stops running and returns the specified value.
Example
function add(a, b) { return a + b;}
console.log(add(5, 3));Q2. Why is the Return Statement important?
The return statement is important because it allows functions to produce results that can be used elsewhere in the program.
Without a return statement, a function cannot send back processed data, making it less useful.
Without a return statement, a function cannot send back processed data, making it less useful.
Q3. What happens if a function does not have a Return Statement?
If a function does not contain a return statement, it automatically returns undefined.
Example
Output
Example
function greet() { console.log("Hello");}
let result = greet();console.log(result);Output
HelloundefinedQ4. Can a function return multiple values in JavaScript?
A function cannot directly return multiple values, but it can return an array or an object containing multiple values.
Example (Array)
Example (Object)
Example (Array)
function getValues() { return [10, 20];}
let values = getValues();console.log(values);Example (Object)
function getUser() { return { name: "John", age: 25 };}Q5. What happens if the Return Statement is written without a value?
If the return statement is used without a value, the function returns undefined.
Example
Example
function test() { return;}
console.log(test());