๐Ÿ“ƒ ํ”„๋ก ํŠธ์—”๋“œ ์ธํ„ฐ๋ทฐ ๋ฌธ์ œ ๋‹ตํ•ด๋ณด๊ธฐ #5 JS์˜ ์ด์ƒํ•œ ์—ฐ์‚ฐ๋“ค

Jake Seoยท2020๋…„ 6์›” 6์ผ
5
post-thumbnail

๐Ÿ“ƒ ํ”„๋ก ํŠธ์—”๋“œ ์ธํ„ฐ๋ทฐ ๋ฌธ์ œ ๋‹ตํ•ด๋ณด๊ธฐ #5 JS์˜ ์ด์ƒํ•œ ์—ฐ์‚ฐ๋“ค

Prologue

๊นƒํ—ˆ๋ธŒ๋ฅผ ๋Œ์•„๋‹ค๋‹ˆ๋‹ค๊ฐ€ ์˜ˆ์ „์— ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž ์ธํ„ฐ๋ทฐ ์งˆ๋ฌธ์ด๋ผ๋Š” ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋ณธ์ ์ด ์žˆ๋‹ค. ์‚ฌ์‹ค ๊ทธ ๋‹น์‹œ์—๋Š” ๊ทธ๋ƒฅ ์Šคํƒ€๋งŒ ๋ˆŒ๋Ÿฌ๋†“๊ณ  ํฐ ๊ด€์‹ฌ์ด ์—†์—ˆ์ง€๋งŒ ์ง€๊ธˆ๋ถ€ํ„ฐ ํ•˜๋‚˜์”ฉ ํ’€์–ด๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค.

๋ฌผ๋ก  ๋งŽ์€ ๋‹ต๋“ค์ด ์ด๋ฏธ ์ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์ž‘์„ฑ๋˜์–ด ์žˆ๊ธด ํ•œ๋ฐ, ์ž‘์„ฑ๋˜์ง€ ์•Š์€ ๊ฒƒ๋“ค๋„ ์žˆ๊ณ  ๋‚ด ๋‹ต์ด๋ž‘ ๋ชจ๋ฒ”๋‹ต์•ˆ์„ ๋น„๊ตํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์„œ ํ•œ๋ฒˆ ํ’€์–ด๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ ์„ ์ •

๊ธฐ์กด ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—๋Š” ๋ฌธ์ œ์˜ ๋ถ„๋ฅ˜๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์ด ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.

  1. General Questions
  2. HTML Questions
  3. CSS Questions
  4. JS Questions
  5. Accessibility Questions (external link)
  6. Testing Questions
  7. Performance Questions
  8. Network Questions
  9. Coding Questions
  10. Fun Questions

๋งค์ผ 1๊ฐ€์ง€์”ฉ ๋Œ์•„๊ฐ€๋ฉฐ ํ’€ ๊ฑด๋ฐ, General Questions ํ•ญ๋ชฉ์—์„œ ๋„ˆ๋ฌด ์ผ๋ฐ˜์ ์ธ ๋ฌธ์ œ๋Š” ํ’€์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค. ๋„ˆ๋ฌด ์ผ๋ฐ˜์ ์ธ ๋ฌธ์ œ์˜ ์ •์˜๋Š” ์‚ฌ๋žŒ๋งˆ๋‹ค ๋‹ต์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

์ด๋ฅผํ…Œ๋ฉด...

What did you learn yesterday/this week? (์–ด์ œ/์ด๋ฒˆ์ฃผ์— ๋ฌด์—‡์„ ๋ฐฐ์› ๋‚˜์š”)
What excites or interests you about coding? (๋ฌด์—‡์ด ๋‹น์‹ ์„ ์ฝ”๋”ฉํ•˜๊ณ  ์‹ถ๊ฒŒ ๋งŒ๋“œ๋‚˜์š”?)
What is a recent technical challenge you experienced and how did you solve it?(์ตœ๊ทผ์— ๊ฒช์€ ๊ธฐ์ˆ ์ ์ธ ์–ด๋ ค์›€๊ณผ ๊ทธ๊ฒƒ์„ ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ–ˆ๋Š”์ง€ ์•Œ๋ ค์ฃผ์„ธ์š”)

์ด๋Ÿฌํ•œ ๊ฒƒ๋“ค์€ ๋‹ต๋ณ€ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๋ฌธ์ œ๋Š” ๊ทธ๋•Œ๊ทธ๋•Œ ๋‹ต์ด ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ 

๋‚˜์˜ ๋‹ต๋ณ€์€ ๋†’์€ ํ™•๋ฅ ๋กœ ํ‹€๋ฆด ์ˆ˜๋„ ์žˆ์œผ๋ฉฐ, ์•„๋‹ˆ๋ฉด ๋งž๊ฒŒ ๊ฐ€๋‹ค๊ฐ€ ์ค‘๊ฐ„์— ์ด์ƒํ•œ ๊ธธ๋กœ ๋น ์งˆ ์ˆ˜๋„ ์žˆ๋‹ค. ๋Œ“๊ธ€์— ์ž์‹ ๋งŒ์˜ ๋‹ต์„ ์˜ฌ๋ ค์ฃผ๋ฉด ๋งค์šฐ ๊ณ ๋งˆ์šธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Q: 10 + '20'์˜ ๊ฐ’์€ ๋ฌด์—‡์ผ๊นŒ์š”?

์›๋ฌธ : What is the value of foo?

var foo = 10 + '20';

A:

์ง์ ‘ ์‹คํ–‰ํ•ด๋ณด๋ฉด ์•„์‹œ๊ฒ ์ง€๋งŒ foo์˜ ๊ฐ’์€ 1020์ด ๋‚˜์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๊ทธ ์ด์œ ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ + ์—ฐ์‚ฐ์ž๋Š” ๋ฌธ์ž์—ด์„ ํ•ฉ์น˜๋Š” concat ๊ธฐ๋Šฅ์ด ์žˆ๊ณ  ๊ทธ๊ฒƒ์„ ๋จผ์ € ๊ณ ๋ คํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

+, -, *, / ์˜ ์‚ฌ์น™์—ฐ์‚ฐ์ค‘ ์˜ค์ง +๋งŒ ์–‘์ชฝ ํ”ผ์—ฐ์‚ฐ์ž ์ค‘ ํ•œ์ชฝ์— ๋ฌธ์ž์—ด์ด ์กด์žฌํ•  ๋•Œ ๋‹ค๋ฅธ ํ•œ์ชฝ๋„ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ์–ด๋ฒ„๋ฆฝ๋‹ˆ๋‹ค.

๋‚˜๋จธ์ง€ ์—ฐ์‚ฐ๋“ค์€ ๋ฌธ์ž์—ด๊ณผ ํ•จ๊ป˜ ์—ฎ์˜€์„ ๋•Œ ๋‹ค๋ฅธ ํ•œ์ชฝ์— Number ํ˜•๋ณ€ํ™˜์„ ์ ์šฉํ•˜์—ฌ ์—ฐ์‚ฐํ•ฉ๋‹ˆ๋‹ค.

Q: (0.1 + 0.2) == 0.3์˜ ๊ฒฐ๊ณผ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”

(0.1 + 0.2) == 0.3 //?

A:

์ •๋‹ต์€ false์ž…๋‹ˆ๋‹ค.

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” double-precision 64-bit binary format IEEE 754์˜ ํ˜•ํƒœ๋กœ ์ˆซ์ž๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ ์ด์ง„์ˆ˜๋กœ ์ˆซ์ž๋ฅผ ์ €์žฅํ•˜๋Š”๋ฐ, ์†Œ์ˆ˜๋ฅผ ์ €์žฅํ•  ๋•Œ๋Š” ๊ฐ€๋” ์ด์ง„์ˆ˜๋กœ ์™„์ „ํ•˜๊ฒŒ ํ‘œํ˜„์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ์†Œ์ˆ˜๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค๋ฉด 10์ง„์ˆ˜ 0.2๋Š” 2์ง„์ˆ˜๋กœ ํ‘œํ˜„ํ•˜๋ ค ํ•ด๋„ ๋Œ€๋žต์ ์œผ๋กœ 0.0011 0011 0011...์˜ ๋ฐ˜๋ณต์œผ๋กœ๋งŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์„ ๋ฟ ์ •ํ™•ํžˆ ํ‘œํ˜„์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฌํ•œ ํŠน์„ฑ ๋•์— 0.1 + 0.2์ด ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๊ณ„์‚ฐ๋˜์ง€ ๋ชปํ•˜๊ณ  0.3๊ณผ ๊ฐ™์ง€๋„ ์•Š๋‹ค๊ณ  ๋‚˜์˜ต๋‹ˆ๋‹ค.

์˜ฌ๋ฐ”๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์œ„ํ•ด์„œ๋Š”
1. ์†Œ์ˆ˜์  ๋ฐ˜์˜ฌ๋ฆผ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ๋„ ๋˜๊ณ 
2. ์†Œ์ˆ˜์— 10์„ ๊ณฑํ•ด 10์ง„์ˆ˜๋กœ ๋งŒ๋“  ๋’ค์— ๊ณ„์‚ฐ ํ›„ ๋‹ค์‹œ ์†Œ์ˆ˜๋กœ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

IEEE 754์˜ ๋‚ด๋ถ€ ๊ตฌ์กฐ๋Š”
Sign bit: 1 bit
Exponent: 11 bits
Significand precision: 53 bits (52 explicitly stored)
์œ„์™€ ๊ฐ™์ด ์ด๋ฃจ์–ด์ ธ์žˆ์Šต๋‹ˆ๋‹ค.

profile
ํ’€์Šคํƒ ์›น๊ฐœ๋ฐœ์ž๋กœ ์ผํ•˜๊ณ  ์žˆ๋Š” Jake Seo์ž…๋‹ˆ๋‹ค. ์ฃผ๋กœ Jake Seo๋ผ๋Š” ๋‹‰๋„ค์ž„์„ ๋งŽ์ด ์”๋‹ˆ๋‹ค. ํ”„๋ก ํŠธ์—”๋“œ: Javascript, React ๋ฐฑ์—”๋“œ: Spring Framework์— ๊ด€์‹ฌ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€