JavaScript
function
김꼬알
2023. 6. 13. 18:17
함수 선언과 호출
// 함수 선언
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 -> 인자를 넣지 않고 함수를 호출하면 함수 자체가 호출됨