-
[100DaysOfCode] 31๊ฐFront-end/100DaysOfCode 2022. 8. 26. 23:56
๐ก ํจ์
ํจ์์ ์ฅ์ : ์ฝ๋์ ์ฌ์ฌ์ฉ
๋ฏธ๊ตญ ๋์ด ๊ธฐ์ค์ผ๋ก ์ฑ์ธ์ด ๋์ง ์ผ๋ง๋ ๋๋์ง ๊ณ์ฐํ๊ณ ์ถ์ ๋
let adultYears = age - 18; // ๋ฏธ๊ตญ ์ฑ์ธ ๋์ด ๊ณ์ฐ let manAge = age - 18; let womanAge = age - 18;
๋ง์ฝ ํ๊ตญ ๋์ด๋ก ๋ฐ๊พธ๊ณ ์ถ๋ค๋ฉด? ์ผ์ผ์ด 'age - 18' ์ฝ๋๋ฅผ ๋ณ๊ฒฝํด์ฃผ์ด์ผ ํ๋ค๐จ
ํจ์ ์ฌ์ฉ
let age = 0 function calculateAge(age) { return age - 18; } let manAge = calculateAge(20); let womanAge = calculateAge(21); console.log(manAge); console.log(womanAge);
ํจ์๋ฅผ ์ฌ์ฉํจ์ผ๋ก์จ ํ๊ตญ ๋์ด๋ก ๋ฐ๊พธ๊ณ ์ถ์ ๊ฒฝ์ฐ ํจ์ ๋ด์ ์๋ ์ซ์๋ง ๋ณ๊ฒฝํด์ฃผ๋ฉด ๋๋ค!
'Front-end > 100DaysOfCode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[100DaysOfCode] 33๊ฐ (0) 2022.09.04 [100DaysOfCode] 32๊ฐ (0) 2022.09.01 [100DaysOfCode] 30๊ฐ (0) 2022.08.23 [100DaysOfCode] 27๊ฐ - 28๊ฐ (0) 2022.08.21 [100DaysOfCode] 26๊ฐ (0) 2022.08.18