1
first();
function first(){
second();
third();
}
function second(){
var b='second';
}
function third(){
console.log(b);
}
3番目の変数bにアクセスしようとしているときにエラーが発生しました。 console.log(b); ^ノードjs:メソッド間でローカル変数にアクセスする方法
にReferenceError:あなたはb
にアクセスしたい場合は、グローバル
first();
var b;
function first(){
second();
third();
}
function second(){
b='second';
}
function third(){
console.log(b);
}
console.log(b);
としてそれを定義するために持っているよりもBが
を見てあなたは読みたいと思うかもしれません[ Javascriptの変数の範囲は何ですか?](https://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript) – Paul