如何解决我们如何将变量从两个函数传递给一个函数?
将变量X和y传递给函数C ... 怎么做?
function a(){
let x = 1;
}
function b(){
let y = 2;
}
function c(){
let z;
z = x + y;
}
解决方法
您必须相应地返回x和y的值,您的函数需要返回数据,然后将其存储在变量中。
function a(){
return 1; // MAKE SURE TO RETURN the data you need from your function A
}
function b(){
return 2; // Return the data from your function B
}
function c(){
let z,x = a(); // Returns 1 inside the X variable
y = b(); // Returns 2 inside the Y variable
z = x + y; // z = 1 + 2
return z // 3
}
c() // 3
https://repl.it/@fernandob/passing-data-from-2-funds#index.js
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。