👋 Hello, I am Seung-ho Ham

🧑🏻‍💻 A Developers who create code that changes the world

카테고리 없음

[DEV] JS 함수

Potato_H 2021. 6. 24. 08:36
반응형

함수 (function)

- 특정 동작(기능)을 수행하는 일부 코드의 집(부분)


//함수 선언
function helloFunc() {
    return 123;
}

let a = returnFunc();

console.log(a); //123


//함수 선언
function sum(a,b) { //a와 b는 매개변수(paraneters)
    return a + b;
}

//재사용
let a = sum(1,2); //1과 2는 인수(Arguments)
let b = sum(7,12);
let c = sum(2,4);

console.log(a,b,c); // 3,19,6 출력


// 기명 함수
// 함수 선언
function hello{
    console.log('hello!');
}

// 익명 함수
// 함수 표현
let world = function() {
    console.log('world');
}

// 함수 호출
hello(); // hello! 출력
world(); // world 출력



// 객체 데이터
const abc = {
    name: 'abc',
    age : 99,
    // 메소드(method)
    getName : function () {
        return this.name;
    }
};

const hisName = abc.getName();
console.log(hisName); // abc

//OR

console.log(abc.getName()); // abc