To return a string from a JavaScript function, use the return statement in JavaScript.
Example
You need to run the following code to learn how to return a string using return statement −
<html> <head> <script> function concatenate(name, subject) { var val; val = name + subject; return val; } function DisplayFunction() { var result; result = concatenate('Amit', ' Java'); document.write (result ); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type = "button" onclick = "DisplayFunction()" value = "Result"> </form> </body> </html>