declare a function with return value in Javascript
Code snippet on how to declare a function with return value in Javascript
function myFunction() {
return 'Hello World';
}
This is a simple example of a Javascript function with a return value. The function starts with the keyword “function” followed by the function name, in this case “myFunction”. Inside of the function, the keyword “return” is used, followed by a value in quotes – in this case, “Hello World”. The function ends with a closing ”}“.
When this function is called, it will execute the code inside it, specifically the line with the “return” keyword. In this case, the return value will be “Hello World”. After the code inside the function is executed, the return value is given back to the code that called the function.