뭉지야 2023. 8. 6. 22:28
728x90

화면에 출력하는거다

 

return을 하면 function은 작동을 멈추고 결과값을 return 하고 끝낸다

 

const calculator = {
  plus: function (a,b){
    return a + b;
    console.log("hello")
  }
}
const plusResult = calculator.plus(2, 3);

 

이렇게 했을때 hello는 출력되지 않는다

 

 

const calculator = {
  plus: function (a,b){
    console.log("hello");
    return a + b;
    console.log("bye");
  }
}

const plusResult = calculator.plus(2, 3);

 

이렇게 하면 hello만 출력되고 bye는 출력되지 않는다!!!

728x90