Arrow functions · 화살표 함수
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Arrow functions
- A shorter way to write a function:
const square = (n) => n * n;. - With a single expression after
=>, the value is returned automatically — noreturn, no{ }.
한국어
화살표 함수
- 함수를 더 짧게 쓰는 방법:
const square = (n) => n * n;. =>뒤에 단일 표현식이 있을 경우 값이 자동으로 반환되며,return이나{ }은 필요 없습니다.
const square = (n) => n * n;
console.log(square(5)); // → 25
English
More than one parameter
- List the parameters in the brackets, separated by commas.
한국어
여러 개의 매개변수
- 괄호 안에 매개변수를 나열하고, 표(,)로 구분하세요.
const add = (a, b) => a + b;
console.log(add(3, 4)); // → 7
English
Watch out
- Need a longer body? Use
{ }and then you must writereturnyourself. - Arrow functions shine as short helpers — you will hand them to
.mapand.filterwhen we reach array methods.
한국어
주의사항
- 본문이 길어질까요?
{ }을 사용하고return을 직접 적어야 합니다. - 화살표 함수는 짧은 보조 함수로 유용합니다. 배열 메서드를 다룰 때
.map과.filter에 전달할 것입니다.
English
Common mistakes
x => x + 1is a short function; with no braces it returns the expression.- Arrow functions are handy as arguments to array methods.
한국어
흔한 실수
x => x + 1은 짧은 함수이며, 중괄호가 없으면 표현식을 반환합니다.- 화살표 함수는 배열 메서드의 인자로 편리하게 사용할 수 있습니다.
English
Now you try
- Write each arrow function.
- Press Check answer to test it.
한국어
이제 직접 해보기
- 각 화살표 함수를 작성하세요.
- 답안 확인을 눌러 테스트해 보십시오.
Write an arrow function triple that returns its argument times 3: const triple = (n) => n * 3;. · 인자의 3배를 반환하는 화살표 함수 triple을 작성합니다: const triple = (n) => n * 3;.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Write an arrow function add with two parameters that returns their sum. · 두 개의 매개변수가 있는 화살표 함수 add을 작성하여 их 합을 반환합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Write an arrow function isEven that returns true when its argument is even (n % 2 === 0). · 화살표 함수(arrow function) isEven을 작성하세요. 인자가 짝수(even)일 때 true을 반환하며, 조건은 n % 2 === 0입니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.