We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES6에서의 예제가 이해가 되지 않음
ES6 { function foo () { return 1 } foo() === 1 { function foo () { return 2 } foo() === 2 } foo() === 1 } ES5 [source, javascript] // only in ES5 with the help of block-scope emulating // function scopes and function expressions (function () { var foo = function () { return 1; } foo() === 1; (function () { var foo = function () { return 2; } foo() === 2; })(); foo() === 1; })(); [참고사이트] http://es6-features.org/#BlockScopedFunctions
The text was updated successfully, but these errors were encountered:
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/block 원래 block statement 가 존재 아래와 같은 구조
{ statement_1; statement_2; ... statement_n; }
그래서 아래와 같은 코드도 가능
var x = 1; { var x = 2; } console.log(x); // 2
x가 2가 나오는 이유는 자바스크립트 var의 스코프는 함수스코프이기 때문
하지만 let으로 바꾸면
let y = 1; { let y = 2; } console.log(y); // 1
블록스코프이기 때문에 1이 나옴
함수선언으로 가면 재미있어지는데
{ function foo () { return 1; } console.log(foo()); { function foo () { return 2; } console.log(foo()); } console.log(foo()); }
각각의 foo가 어떤 함수를 가리키는지 브라우져를 열어서 돌려보자
Sorry, something went wrong.
해결완료
No branches or pull requests
ES6에서의 예제가 이해가 되지 않음
ES6
{
function foo () { return 1 }
foo() === 1
{
function foo () { return 2 }
foo() === 2
}
foo() === 1
}
ES5 [source, javascript]
// only in ES5 with the help of block-scope emulating
// function scopes and function expressions
(function () {
var foo = function () { return 1; }
foo() === 1;
(function () {
var foo = function () { return 2; }
foo() === 2;
})();
foo() === 1;
})();
[참고사이트]
http://es6-features.org/#BlockScopedFunctions
The text was updated successfully, but these errors were encountered: