Created
September 6, 2021 14:14
-
-
Save pota-gon/60f1e238c28613eeef794af9d1515a51 to your computer and use it in GitHub Desktop.
JavaScript の const を理解するためのコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sum += 10 は、自己代入なので | |
let sum = 0; | |
sum += 10; | |
// const は再代入禁止だから分かった。 | |
const data = []; | |
data.push(10); | |
// Q. num は let じゃなくても動くのなぜ? | |
// A. For文はループごとに別スコープになるから | |
for (let i = 0; i < 5; i++) { | |
const num = i; | |
console.log(num); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment