for (์ด๊ธฐ๊ฐ; ์กฐ๊ฑด์; ์ฆ๊ฐ์) {
// ์คํํ ์ฝ๋
}
while (์กฐ๊ฑด) {
}
// ํจ์์ ์ธ๋ฌธ์ผ๋ก ์ ์ํ ํจ์
function greeting () {
console.log('hello world')
};
// ํจ์ํํ์์ผ๋ก ์ ์ํ ํจ์
let greeting = function () {
console.log('hello world')
};
function greeting () {
console.log('hello world')
};
greeting() // 'hello world'
function greeting (name) {
//name : ์ ๋ฌ๋ฐ์ ์ธ์๊ฐ ๋งค๊ฐ๋ณ์์ ๋ค์ด์์ ํจ์๋ ์คํ๋๋ค.
console.log('hello ' + name);
}
greeting('kimcoding');// 'hello kimcoding'
// ํจ์์ด๋ฆ () <- ๊ดํธ ์์ ์ธ์๋ฅผ ๋ฃ์ด ์ ๋ฌํ๋ค.
function add (x, y) {
return x + y; // ๋ฐํ๋ฌธ
}
//ํจ์๋ฅผ ํธ์ถํ๊ณ ์คํ๋ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์์ result ๋ณ์์ ๋ฐ๋ ๋ฐฉ๋ฒ
let result = add(3, 2) + add(5, 7);
console.log(result); // 17