Replies: 1 comment
-
답변함수 스코프는 변수의 접근성이 함수 내부로 제한되는 반면, 블록 스코프는 변수의 접근성이 코드 블록 내부로 제한됩니다. 또 블록 스코프는 변수의 재선언을 허용하지 않고, 변수 끌어올리기를 지원하지 않으며, 전역 변수에 접근할 수 없습니다. // 함수 스코프
function myFunction() {
var x = 10;
if (true) {
var y = 20;
}
console.log(x); // 10
console.log(y); // 20
}
// 블록 스코프
function myFunction() {
let x = 10;
if (true) {
let y = 20;
console.log(y); // 20
}
console.log(x); // 10
// console.log(y); // ReferenceError: y is not defined
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
각각의 정의와 예시를 들어 설명해주세요.
Beta Was this translation helpful? Give feedback.
All reactions