JavaScript 函数调用并返回结果
对于外部函数调用,请使用 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
廣告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP