Function
Function
์ด๋ ํ๊ฒ์ ๊ธฐ๋ฅ ์ํ๋ ๋งํผ ์ธ ์ ์๋ ์ฝ๋์ด๋ค.
console -> object , log -> fuction
function sayHello (e,a){ //(e) -> ์ธ๋ถ์ ์๋ ๋ฐ์ดํฐ๋ฅผ ์ฝ๋ ํจ์๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ
console.log('HEllo',e,"you have" a);
//console.logํจ์๋ argument๋ฅผ ๋ฌดํํ๊ฒ ๊ฐ์ง ์ ์๋ค.
};
sayHello("Nice",15); //Hello Nice you have 15
// Nice ๋ argument ์ธ์ ์ด๋ค.
console.log("Hi"); // Hi
Function Fun
function sayHello(name,age){
console.log('HEllo'+ name + "you have" + age + "years old");
};
sayHello{"boo" , 17}; // Hello boo you have 17 years old
function sayHello(name,age){
return(`HEllo ${name} you are ${age} years old`);
// return -> ๋ฐํํด์ค
};
const greetBoo = sayHello("Boo", "17")
console.log(greetBoo);// Hello boo you have 17 years old
const calculator = {
plus: function (a, b)[
return a + b;
}
}
const calculator.plus(5,5)
console.log(plus) // 10
Function DOM
DOM(Document Object Model)ํํ๋ก ๋ณ๊ฒฝ์ด ๊ฐ๋ฅํจ
const title = document.getElementByld("title"); // document -> object
const title = document.quearySelector("#title") // id title์ ์ง์
title.innerHTML = "Hi js" // html์ Hi js ์ถ๋ ฅ๋จ
// html์ DOM๊ฐ์ฒด๋ก ๋ฐ๊ฟ ์ ์๋ค. Html ์์ ํ ์ ์๋ค.
title.style.color = "blue"; // ๊ธ์จ ์๊น์ด ๋ธ๋ฃจ๋ก ๋ฐ๋
console.log(title); // title id๊ฐ์ ๊ฐ์ง html element๋ฅผ ๋ถ๋ฌ๋
console.log(title); // ํด๋น ์ ๋ณด๋ฅผ ๋ณผ ์ ์์
document.title = "Hello" // ํ์ดํ์ด Hello๋ก ๋ฐ๋
Last updated
Was this helpful?