리턴값이 있는 함수

return문은 함수에서 결괏값을 반환할 때 사용합니다.

리턴값이 있는 함수

function 함수 이름(){ //실행코드 return 리턴값; } let 변수 = 함수명();//함수호출

function func4(){
    let str = "함수가 실행되었습니다.";
    return str;
}
let value = func4();
document.write(value);

리턴값이 있는 함수(종료)

function func6(){
    document.write("함수가 출력되었습니다.6");
    return;
    document.write("함수가 출력되었습니다.7");
}
func6();

//함수가 출력되었습니다.6

리턴값 + 매개변수

function func5(num1,num2){

    return num1 + num2;
}
let result = func5(100,200);
document.write(result);

//300

평균점수 구하기

이미지 슬라이드

Last updated

Was this helpful?