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

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

by 한선용, 이선 브라운
July 2017
Beginner to intermediate
464 pages
10h 38m
Korean
Hanbit Media, Inc.
Content preview from 러닝 자바스크립트: ES6로 제대로 입문하는 모던 자바스크립트 웹 개발
149
5
표현식과 연산자
let
n
=
0
;
while
(
true
) {
n
+ =
0
.
1
;
if
(
n
===
0
.
3
)
break
;
}
console
.
log
(`
Stopped
at
${
n
}`);
이 프로그램을 실행하면 예상 외의 결과에 놀랄 겁니다. 이 루프는
0
.
3
에서 멈추지 않고 그 값
을 살짝 피한 다음 영원히 실행됩니다. 이 결과는
0
.
1
이 더블 형식으로 정확히 나타낼 수 없는
값이기 때문입니다.
0
.
1
은 이진 표현으로 나타낼 수 있는 숫자들 사이에 걸쳐 있습니다. 따라
서 이 루프를 세 번째 반복할 때
n
의 값은
0
.
30000000000000004
이므로 테스트는
false
이고,
유일한 종료 조건이 실패하게 됩니다.
Number
.
EPSILON
과 관계 연산자를 사용해서 ‘느슨하게’ 비교하고 성공적으로 루프를 빠져나갈
수 있습니다.
let
n
=
0
;
while
(
true
) {
n
+ =
0
.
1
;
if
(
Math
.
abs
(
n
-
0
.
3
) <
Number
.
EPSILON
)
break
;
}
console
.
log
(`
Stopped
at
${
n
}`);
테스트하는 숫자(
n
)에서 비교 대상 (
0
.
3
)을 뺀 다음 절댓값을 취하는 방식을 썼습니다(
Math
.
abs
16
장에서 설명합니다). 그냥
n
0
.
3
보다 큰지 확인하는 간단한 방법도 있지만, 여기서
사용한 방법은 두 개의 더블 형식이 ...
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