Skip to Content
러닝 자바스크립트: ES6로 제대로 입문하는 모던 자바스크립트 웹 개발
book

러닝 자바스크립트: ES6로 제대로 입문하는 모던 자바스크립트 웹 개발

by 한선용, 이선 브라운
July 2017
Beginner to intermediate
464 pages
10h 38m
Korean
Hanbit Media, Inc.
Content preview from 러닝 자바스크립트: ES6로 제대로 입문하는 모던 자바스크립트 웹 개발
189
7
스코프
7.2
정적 스코프와 동적 스코프
프로그램의 소스 코드를 살펴보는 건 그 프로그램의
정적 (어휘적,
lexical
) 구조
를 살펴보는
겁니다. 하지만 프로그램을 실제 실행하면 실행 흐름은 이곳 저곳으로 움직입니다. 함수 두 개
를 쓰는 프로그램이 있다고 합시다.
function
f1
() {
console
.
log
('
one
');
}
function
f2
() {
console
.
log
('
two
');
}
f2
();
f1
();
f2
();
정적으로 보면 이 프로그램은 단순히 위에서 아래로 읽어내리는 문의 연속입니다. 하지만 이
프로그램을 실행하면 실행 흐름은 읽는 순서와 다릅니다.
f1
f2
보다 먼저 정의됐지만,
f2
함수 바디가 실행된 다음
f1
으로, 다시
f2
로 넘어갑니다.
자바스크립트의 스코프는
정적
입니다. 소스 코드만 봐도 변수가 스코프에 있는지 판단할 수 있
다는 뜻입니다. 다만, 소스 코드만 봐도 즉시 스코프를
분명히
알 수 있다는 뜻은 아닙니다. 이
장에서 꼼꼼히 살피다 보면 스코프를 판단할 수 있는 몇몇 예제를 찾아볼 수 있을 겁니다.
정적 스코프는 어떤 변수가 함수 스코프 안에 있는지 함수를
정의할 때
알 수 있다는 뜻입니다.
호출할 때
알 수 있는 것은 아닙니다. 다음 예제를 보십시오.
const
x
=
3
;
function
f
() {
console ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

웹 애플리케이션 보안: 정찰, 공격, 방어 세 단계로 배우는 웹 애플리케이션 보안의 모든 것

웹 애플리케이션 보안: 정찰, 공격, 방어 세 단계로 배우는 웹 애플리케이션 보안의 모든 것

최용, 앤드루 호프먼

Publisher Resources

ISBN: 9788968483387