๋งค๊ฐ๋ณ์(Parameters)
- primitive parameters (value๋ฅผ ์ ๋ฌ)
- object parameters (reference๋ฅผ ์ ๋ฌ)
function changeName(obj) {
obj.name = 'coder';
}
const noran = {name : 'noran'};
changeName(noran);
console.log(noran);
๋๋จธ์ง ๋งค๊ฐ๋ณ์(rest parameters)
function printAll(...args) {
for (let i = 0; i < arg.length; i++) {
console.log(arg.[i]);
}
}
printAll('noran','javascript','goodcoding');
๋งค๊ฐ๋ณ์ ์์ ...๋ฅผ ๋ถ์ด๋ฉด ๋ฐฐ์ด ํํ๋ก ์ ๋ฌ๋๋ค.
์ ์ฝ๋๋ for of ๋ฌธ์ ํตํด ๊ฐ๋จํ๊ฒ ๋ฐ๊ฟ ์ ์๋ค.
for of๋ฌธ์ผ๋ก ์์
function printAll(...args) {
for (const arg of args) {
console.log(arg);
}
}
printAll('noran','javascript','goodcoding');
์ ์ฝ๋๋ ๋ํ ๋ฐฐ์ดํจ์๋ฅผ ํตํด ๋ ๊ฐ๋จํ๊ฒ ๋ฐ๊ฟ ์ ์๋ค.
forEach๋ก ์์
function printAll(...args) {
args.forEach((arg) => console.log(arg));
}
printAll('noran','javascript','goodcoding');
์ถ์ฒ : ๋๋ฆผ์ฝ๋ฉ https://www.youtube.com/@dream-coding / MDN https://developer.mozilla.org/ko
'๐จ JavaScript > ๊ฐ๋ ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋๋ฆผ์ฝ๋ฉ ์ธ] ์ฝ๋ฐฑํจ์ (Callback function) (0) | 2022.04.22 |
---|---|
[๋๋ฆผ์ฝ๋ฉ] Early return, early exit? (0) | 2022.04.21 |
[mdn] ๊ธฐ๋ณธ๊ฐ ๋งค๊ฐ๋ณ์ (0) | 2022.04.15 |
[์ํ์ฝ๋ฉ, ๋๋ฆผ์ฝ๋ฉ, ์ฝ๋ฉ์๋ง] ์ฐ์ฐ์(Operator)์ break, continue (0) | 2022.04.14 |
[์ฝ๋ฉ์๋ง ์ธ] ๊ฐ์ฒด ๋ฆฌํฐ๋ด๊ณผ ๊ฐ์ฒด ์ ๊ทผ๋ฒ, ๊ทธ๋ฆฌ๊ณ ์์ฑ์ ํจ์ (0) | 2022.04.14 |