์ ์ถํ ํด๋ ์ด๋ฆ : | 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!$