Skip to content

Instantly share code, notes, and snippets.

@pota-gon
Created September 6, 2021 14:14
Show Gist options
  • Save pota-gon/60f1e238c28613eeef794af9d1515a51 to your computer and use it in GitHub Desktop.
Save pota-gon/60f1e238c28613eeef794af9d1515a51 to your computer and use it in GitHub Desktop.
JavaScript の const を理解するためのコード
// 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