1. function
function hello() {
// 실행 코드
console.log (3456);
}
//함수 호출
hello(); // 3456
2. return
function num(){
return 123;
}
let a = num();
console.log (a); // 123
3. 매개변수와 인수
function sum (a,b) { //a와 b는 매개변수
return a+b
}
let a = sum(1,2); // 1과 2는 인수
let b = sum(3,4);
console.log (a, b, c); // 3,7
4. 기명함수
5. 익명함수
// 함수 선언
function hello () {
console.log ('hello!');
}
// 함수 표현
let world = function() {
console.log ('world');
}
// 함수 호출
hello(); // hello!
world(); // world
6. 메소드
// 객체 데이터
const rookie = {
name: 'urim',
age: 20,
// 메소드
getName: function () {
return this.name;
}
};
const hisName = rookie.getName();
console.log(herName); // urim
// 혹은
console.log(rookie.getName()); // urim