function add(a, b){
return a + b;
}
add(2, 3);
function
return
을 쓰면 return
오른쪽의 값
을 반환해준다.
함수를 호출한 자리 add(2, 3)
에 5
를 반환한다.
function hello() {
console.log("hi");
return abc;
console.log("wow");
}
hello();
return
을 사용하면 함수가 끝나는 효과
가 있다.
return
위에 console.log("hi")
는 실행되지만, return
아래에 console.log("wow")
는 실행되지 않는다.