Lesson “Return a Value From a Function With Return,” says “You can use a return statement to send a value back out of a function.” Yet I can’t figure out what that is supposed to mean. Could someone explain it in more detail for me?
Thanks for taking the time to explain this to me!
Also the return statement is used in some cases to stop the code executing further. For example in node js(server side javascript in case you don t know)
if for some reason you encounter an error you can return
back a response to prevent the code going further and trying to send 2 responses for example which would crash your app. Also inside a function the code you write after return it won t be executed. You can also return another function that returns a value and you can grab that value.
This is more explicit in some other languages. Take this C/C++ code, for instance:
void hello(){
printf("Hello World");
}
bool test(){
return true;
}
int main(){
if(test){
hello();
}
return 0;
}
Here, we have three functions. main() returns an integer, test() returns a boolean value, and hello() is void and just prints “Hello World” without returning anything.
could you pleas give me an example When exactly we don’t use Return statement?