Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Latest commit

ย 

History

History
42 lines (36 loc) ยท 1.83 KB

ex01.md

File metadata and controls

42 lines (36 loc) ยท 1.83 KB

Exercise 01 - ๋ˆ„๊ตฐ์ง€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ์•ˆ๋…•!

์ œ์ถœํ•  ํด๋” ์ด๋ฆ„ : ex01
์ œ์ถœํ•  ํŒŒ์ผ ์ด๋ฆ„ : helloSomeone.js, package.json
์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์™ธ๋ถ€ ๋ชจ๋“ˆ : ์—†์Œ
์ฐธ๊ณ ์‚ฌํ•ญ : ์—†์Œ

์‹คํ–‰ ์‹œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ ธ์™€ ์ธ์‚ฌ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜ helloSomeone์„ ์ž‘์„ฑํ•˜์„ธ์š”. ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ๋Š” ๋ฌธ์ž์—ด, ์ˆซ์ž, NaN, undefined, null์ด ๋“ค์–ด์˜ฌ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์–ด๋–ค ๋งค๊ฐœ๋ณ€์ˆ˜๋ƒ์— ๋”ฐ๋ผ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋™์ž‘์„ ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฌธ์ž์—ด์ด ๋“ค์–ด์˜จ ๊ฒฝ์šฐ, "Hello ๋ฌธ์ž์—ด!" ์„ ์ถœ๋ ฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๋ฌธ์ž์—ด์ด ๋นˆ ๋ฌธ์ž์—ด์ด๋ผ๋ฉด "Who are you?" ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  • ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ null ์ด ๋“ค์–ด์˜จ ๊ฒฝ์šฐ, "I am null and void" ๋ฅผ ์ถœ๋ ฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
  • ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ˆซ์ž๊ฐ€ ๋“ค์–ด์˜จ ๊ฒฝ์šฐ, "My age is ์ˆซ์ž" ๋ฅผ ์ถœ๋ ฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๋‹จ, ์ˆซ์ž๊ฐ€ ์Œ์ˆ˜๋‚˜ 0 ์˜ ๊ฒฝ์šฐ "I am Benjamin Button!" ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  • ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ NaN๊ฐ€ ๋“ค์–ด์˜จ ๊ฒฝ์šฐ, "Age is just a number" ๋ฅผ ์ถœ๋ ฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
  • ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ undefined๊ฐ€ ๋“ค์–ด์˜จ ๊ฒฝ์šฐ "Nobody can define me!" ๋ฅผ ์ถœ๋ ฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’ก ํ…Œ์ŠคํŠธ์‹œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๊ฐ€ ์ ํ˜€ ์žˆ๋Š” ํŒŒ์ผ์„ ํด๋”์— ๋„ฃ์–ด ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

// test.js
import helloSomeone from './helloSomeone.js'
helloSomeone("42");
helloSomeone("");
helloSomeone(null);
helloSomeone(42);
helloSomeone(-1);
helloSomeone(NaN);
helloSomeone(undefined);
> node test.js | cat -e
(node:87794) ExperimentalWarning: The ESM module loader is experimental.
Hello 42!$
Who are you?$
I am null and void$
My age is 42$
I am Benjamin Button!$
Age is just a number$
Nobody can define me!$