JavaScript outsider function call and return the result

JavascriptWeb DevelopmentObject Oriented Programming

Use the return keyword for outsider function call. Following is the code −

Example

var substractMethod = function () {
   var firstValue =1000, thirdValue= 200;
   var divideMethod = function (){
      var secondValue =500;
      console.log("The result of
      divideMethod()="+(firstValue/secondValue));
      return (firstValue-secondValue);
   }
   return divideMethod;
}
var result = subtractMethod();
console.log("The result of substractMethod()="+result());

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo198.js.

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo198.js
The result of divideMethod()=2
The result of subtractMethod()=500
raja
Published on 14-Sep-2020 12:26:31
Advertisements