๐Ÿ›น [JS] | ํ•จ์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜ arguments , ...args

๐Ÿ”น arguments

  • ์ธ์ž๊ฐ’๋“ค์ด arguments์— ๋ฐฐ์—ด ํ˜•์‹์œผ๋กœ ์ •๋ฆฌ๊ฐ€ ๋œ๋‹ค.
  • ์ธ์ž์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ƒ๊ด€์ด ์—†๋‹ค.
      function sumAll() {
        var sumAll = 0;
        for (var i = 0; i < arguments.length; i++) {
        	sumAll += arguments[i];
        }
        console.log("arguments๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ตฌํ•œ ์ด ํ•ฉ : " + sumAll);
      }

๐Ÿ”น ...args

arguments๋ž‘ ๋˜‘๊ฐ™๋‹ค

      function sumAllR(...args) {
        var sumAllR = 0;
        for (var i = 0; i < args.length; i++) {
          sumAllR += args[i];
        }
        console.log("args๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ตฌํ•œ ์ด ํ•ฉ : " + sumAllR);
      }

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ