実行されているjavascriptファイルの順序を把握したいと思います。私は以下の例を持っています。どちらの方法が正しいのかを教えてください。Javascriptコードが実行される順序
//JS gets read from top to bottom:
var hello = 6; //JS sees a varaible declared, it stores variable hello in memory
hello = 4; //Then, JS sees a change to var hello, change the value of hello in the same spot of the memory
console.log(hello); //Lastly, JS sees it needs to execute this function, grabs the value of variable of hello from the memory
// OR is it like:
var hello = 6; //JS sees this is not a function, ingores
hello = 4; //JS sees this is not a function, ingores
console.log(hello); //Then JS sees it needs to execute this function, it goes back to the top of the file to look for variable hello
最後に、このトピックについて、私が深く掘り下げるためのリソースがありますか?最後に、私はjavascriptをマスターするために探しています、あなたが推薦する高度なjavascriptの本はありますか?
何ですか?なぜ関数外の 'var'宣言を無視すべきですか?あるいは 'var'宣言が値が必要になるまで実行されないということですか?それは多くのバックトラックを必要とするので、最初の方法は正しいと思います。いずれにしても、変数の宣言と関数宣言を理解する必要があります。 'var hello = 6;'は実際には 'var hello 'と解釈されます。 hello = 6; 'ここで' var hello; 'は関数スコープまたはスクリプトスコープに置かれます。 – Xufox