How to return a string from a JavaScript function?

JavascriptWeb DevelopmentFront End Technology

To return a string from a JavaScript function, use the return statement in JavaScript.


You need to run the following code to learn how to return a string using return statement −

         function concatenate(name, subject) {
            var val;
            val = name + subject;
            return val;
         function DisplayFunction() {
            var result;
            result = concatenate('Amit', ' Java');
            document.write (result );
      <p>Click the following button to call the function</p>
         <input type = "button" onclick = "DisplayFunction()" value = "Result">
Updated on 19-Jun-2020 11:43:44