DEV Community

Himanshupal0001
Himanshupal0001

Posted on

Return Statement in Coding Languages

This blog is for all the new comers in coding world. This article will cover the most common yet crucial part of any programing language that is The return statement

What is return statement

Return state is used in functions.

A return statement causes execution of the function to leave the current function and resume at the point in the code immediately after where the function was called. Return statements in many languages allow a function to specify a return value to be passed back to the code that called the function.

It is important to understand that a return statement is not stopping the execution of a whole code file but a certain function, because it is function scoped.

For example--


function printMsg() {
return 'hi'
}

printMsg();


//output
hi
Enter fullscreen mode Exit fullscreen mode

Usecases

Return statement is useful in many cases. It is mostly used to get the desired output from a function.

It can be used to get a certain value out of a function or getting modified data.

For example--


function greetings(name){
return ('Hi'+name)
}

greetings('John');

}

//output
Hi John
Enter fullscreen mode Exit fullscreen mode

In the above example the function it taking an argument and returning it with an appended string.

Conclusion

I hope you understand the very basic usecase of return statement. Please comment if you have any query or suggestions to improve the overall content deliveriness.

Top comments (0)