How to return a value from a JavaScript function?

To return a value from a JavaScript function, use the return statement in JavaScript. You need to run the following code to learn how to return a value −


         function concatenate(name, age) {
            var val;
            val = name + age;
            return val;
         function DisplayFunction() {
            var result;
            result = concatenate('John ', 20) ;
            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

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started