함수내에서 return 문을 실행하면 나머지 부분을 실행하지 않고 즉시 프로그램의 제어를 반환한다.
반환값이 지정되지 않은 경우 undefined 가 반환된다.
function returnTest(){
return;
console.log("ignored?")
}
var test = returnTest(); // ignored 출력 X
console.log(test); // undefined
함수를 new 전치 연산자와 함께 실행하였을때
반환값이 객체가 아닌 경우 반환값은 this( 새로운 객체 ) 가 된다.
// 객체를 반환
function Test(){
console.log(this);
return {}
}
var test = new Test(); // Test {}
console.log(test) // {}
// 문자열 반환
function Test2(){
console.log(this);
return "hi";
}
var test2 = new Test2(); // Test2 {}
console.log(test2); // Test2 {}
// 숫자 반환
function Test3(){
console.log(this);
return 3;
}
var test3 = new Test3(); // Test3 {}
console.log(test3); // Test3 {}
// 반환값 없음
function Test4(){
console.log(this);
return;
}
var test4 = new Test4(); // Test4 {}
console.log(test4); // Test4 {}

