[JavaScript] function μƒμ„±μž

λ””λ”©Β·2022λ…„ 10μ›” 23일
0

Section

λͺ©λ‘ 보기
2/18
post-thumbnail

πŸ•– DAY +2 / 2022. 10. 21

SEB FE / Section1 / Unit3 / JavaScript 기초 μ œμ–΄λ¬Έ



πŸ“Œ Today I Learned

  • ν•¨μˆ˜ μ„ μ–Έλ¬Έ
  • ν•¨μˆ˜ ν‘œν˜„μ‹
  • ν™”μ‚΄ν‘œ ν•¨μˆ˜

πŸ’¬ ν•¨μˆ˜ μ„ μ–Έλ¬Έ

  • ν•¨μˆ˜μ— λ§žλŠ” ν‚€μ›Œλ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ μ„ μ–Έ()

예제

function plus2(input) {
         input = input + 2;
         return input;
}
console.log(plus2(8));
// expected output: 10

function multiply(a, b) {
         a, b = a * b;
         return a, b;
}
console.log(multiply(5, 2));
// expected output: 10



πŸ’¬ ν•¨μˆ˜ ν‘œν˜„μ‹

let, const - λ³€μˆ˜ μ„ μ–Έ
function - ν•¨μˆ˜ μ„ μ–Έ

function μ„ μ–Έλ¬Έ μ•ˆμ— let, const μ‚¬μš© μ‹œ ν•¨μˆ˜ ν‘œν˜„μ‹μ΄ λœλ‹€.

예제

let plus2 = function(input) {
            input = input + 2;
            return input;
}
console.log(plus2(4));
// expected output: 6

let multiply = function(a, b) {
               a, b = a * b;
               return a, b;
}
console.log(multiply(3, 4));
// expected output: 12

const plus = new Function('a', 'b', 'return a + b');
console.log(plus(4, 5));
// expected output: 9



πŸ’¬ ν™”μ‚΄ν‘œ ν•¨μˆ˜

λ§€κ°œλ³€μˆ˜κ°€ ν•˜λ‚˜μΌ λ•Œ () μƒλž΅μ΄ κ°€λŠ₯ν•˜κ³ , ν•¨μˆ˜ λ‚΄λΆ€κ°€ ν•˜λ‚˜μ˜ 문으둜 κ΅¬μ„±λœλ‹€λ©΄ {}λ₯Ό μƒλž΅ν•  수 μžˆλ‹€.

μ˜ˆμ‹œ

let plus2 = input => input + 2;
plus2(3)
// expected output: 5

let multiply = (a, b) => (a * b);
multiply(3, 4)
// expected output: 12



πŸ‘€ λŒμ•„λ³΄κΈ°

ν•¨μˆ˜ 선언문을 μž‘μ„±ν•˜κ³  ν‘œν˜„μ‹μœΌλ‘œ λ°”κΏ”μ„œ 짜보고, κ·Έκ±Έ λ‹€μ‹œ ν™”μ‚΄ν‘œ ν•¨μˆ˜λ‘œ μ§œλ³΄λ©΄μ„œ μ’€ 더 이해할 수 있게 된 것 κ°™λ‹€.
function은 값을 λ°˜ν™˜ν•˜κ³  λ‚˜λ©΄ μ’…λ£Œλœλ‹€.
ν•¨μˆ˜λŠ” ν—·κ°ˆλ¦¬κΈ° μ‰¬μš΄ λ“― ν•˜λ©΄μ„œ 닡을 λ”± μ•Œλ € μ£ΌλŠ” 것이... 쑰금 더 λ³΅μŠ΅ν•΄ 보자.
80퍼 μ •λ„λŠ” 이해가 된 것 κ°™λ‹€.

profile
λ¬΄μ‚¬μ™€μš”... μ—΄κ³΅ν–μš”...

0개의 λŒ“κΈ€