How does JavaScript 'return' statement work?

JavascriptWeb DevelopmentFront End Technology

A JavaScript function can have an optional return statement. This is required if you want to return a value from a function. This statement should be the last statement in a function.


You can try to run the following code to work with return statement in JavaScript −

         function concatenate(first, last) {
            var full;
            full = first + last;
            return full;

         function DisplayFunction() {
            var result;
            result = concatenate('John', ' Wright');
            document.write (result );
      <p>Click the following button to call the function</p>

         <input type = "button" onclick = "DisplayFunction()" value = "Call Function">
Published on 16-Feb-2018 12:23:23