Node.js Node js:如何访问方法之间的局部变量

Node.js Node js:如何访问方法之间的局部变量,node.js,Node.js,尝试访问第三个()中的变量b时出错,请提供帮助 控制台日志(b); ^ ReferenceError:b未定义如果要访问b,则必须将其定义为全局 first(); function first(){ second(); third(); } function second(){ var b='second'; } function third(){ console.log(b); } 看我的垃圾桶你可能想看看谢谢,它很好用。 first(); var

尝试访问第三个()中的变量b时出错,请提供帮助 控制台日志(b); ^


ReferenceError:b未定义

如果要访问
b
,则必须将其定义为全局

first();
function first(){
    second();
    third();
}
function second(){
    var b='second';
}
function third(){
    console.log(b);
}

看我的垃圾桶

你可能想看看谢谢,它很好用。
    first();
 var b;
  function first(){
     second();
    third();
 }
function second(){
     b='second';
}
function third(){
    console.log(b);
}

console.log(b);