외부인 함수 호출에는 return 키워드를 사용합니다. 다음은 코드입니다 -
예시
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()); 위의 프로그램을 실행하려면 다음 명령을 사용해야 합니다 -
node fileName.js.
여기에서 내 파일 이름은 demo198.js입니다.
출력
이것은 다음과 같은 출력을 생성합니다 -
PS C:\Users\Amit\javascript-code> node demo198.js The result of divideMethod()=2 The result of subtractMethod()=500