1. Function 사용법

2. Function 데이터 받기

3. Function Return

4. Document Object

5. HTML in Javascript

1. Function 사용법

1-1) Function이 없는 경우

// Function이 없는 경우
console.log("Hello my name is Nico.");
console.log("Hello my name is Ssu");
console.log("Hello my name is Simon.");
…

1-2) Function이 있는 경우

// function이 있는 경우
function sayHello() {
	console.log("Hello my name is"); 
}

// sayHello를 실행될 때마다 console.log가 실행됨.
sayHello();
sayHello();
sayHello();

2. Function 데이터 받기

2-1) 인수(argument)가 하나일 때

// 인수로 어떤 데이터가 들어오면 
// nameOfPerson이라는 변수 이름을 쓰게 되는 거임.
function sayHello (nameOfPerson) {  // 인수는 두 개도 됨.
	console.log(nameOfPerson);
}

sayHello("nico");
sayHello("dal");
sayHello("lyn");

2-2) 인수가 두 개 일때

function sayHello (nameOfPerson, age) {
	console.log("Hello My name is" + nameOfPerson + "and I'm " + age);
}

sayHello("nico", 12);
sayHello("dal", 14);
sayHello("lyn", 24);

3. Function Return

3-1) Return 타입이 Integer일 때

const age = 96;

function calculateKrAge(ageOfForeigner) {
	return ageOfForeigner + 2;
}

const krAge = calulateKrAge(age);

console.log(krAge);

3-2) Return 타입이 String일 때

const age = 96;

function calculateKrAge(ageOfForeigner) {
	ageOfForeigner + 2;
	return "hello";
}

const krAge = calulateKrAge(age);

console.log(krAge);

4. Document Object

4-1) Document : 브라우저에 이미 존재하는 Object

4-2) 자바스크립트

document.title = "Hello From JS!!!";

4-3) HTML

Untitled

4-4) View

Untitled

5. HTML in Javascript

5-1) HTML

<html>
	<body>
		<h1 id="title">Grab me!!!</h1>
		<script scr="app.js"></script>
	</body>
</html>

5-2) Javascript

document.getElementById("title");

5-3) dir(object) 메소드

const title = document.getElementById("title");

console.dir(title);