+prompt의 관해 질문드립니다.

21.07.21 18:37 작성 조회수 99

0

function Accumulator(startingValue) {

  this.value = startingValue;

  this.read = function (){

    this.value += +prompt("number", 0);

  } 

}

let accumulator = new Accumulator(1); // 최초값: 1

accumulator.read(); // 사용자가 입력한 값을 더해줌

accumulator.read(); // 사용자가 입력한 값을 더해줌

alert(accumulator.value); // 최초값과 사용자가 입력한 모든 값을 더해 출력함

여기서 prompt앞에 +를 붙여주면 prompt 입력값이 number type으로 바뀌는데 이유가 궁금합니다. number()매소드를 나타내는 건가요??

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!