함수 선언과 호출
// 함수 선언
function doSomething() {
console.log('hello');
}
// 함수 호출
doSomething(); // hello
// 함수 선언
function add(a, b) {
const sum = a + b;
return sum;
}
// 함수 호출
const result = add(1, 2);
console.log(result); // 3
// 함수 선언
function doSomething(add) {
console.log(add);
const result = add(2, 3);
console.log(result);
}
function add(a, b) {
const sum = a + b;
return sum;
}
// 함수 호출
doSomething(add); // 5 -> 인자를 넣지 않고 함수를 호출하면 함수 자체가 호출됨
'JavaScript' 카테고리의 다른 글
promise (0) | 2023.06.23 |
---|---|
callback (0) | 2023.06.22 |
JSON (1) | 2023.06.13 |
Array APIs (0) | 2023.06.12 |
Array (0) | 2023.06.12 |