티스토리 뷰

JavaScript

[JavaScript] 5식 - Function (함수)

baegofda_ 2020. 7. 12. 15:59

* Function (함수)

  • 기능적인 요소를 부여해준것
function sayHello() {         //sayHello 라는 함수 선언
    console.log("hello!");
}

sayHello();                   //함수 호출
                              // hello!
                              
// sayHello([args]);
function sayHello(potato) {
    console.log("hello!", potato);
}

sayHello("haha");             // hello! haha  

// sayHello([args1, args2]);
function sayHello(potato, caca) {
    console.log("hello!", potato, "you", caca);
}

sayHello("haha", 25);

* more

function sayhello(name, age) {
    console.log("hello " + name + " you " + age + " me ");
}

sayhello("Dale", 25); 
// hello Dale you 25 me 

function sayhello(name, age) {
    console.log(`hello ${name} you ${age} me `);
}

sayhello("Dale", 25); 
// hello Dale you 25 me 

function sayhello(name, age) {
    console.log(`hello ${name} you ${age} me `);
}

const greetDale = sayhello("Dale", 25);

// greetDale은 sayhello의 return 값이다

console.log(greetDale)
// hello Dale you 25 me 
// undefined

const calculator = {
    plus: function (a, b) {
        return a + b;
    }
}

const plus = calculator.plus(5, 5);
console.log(plus); // 10

'JavaScript' 카테고리의 다른 글

[JavaScript] 8식 - classList, toggle  (0) 2020.07.12
[JavaScript] 7식 - if  (0) 2020.07.12
[JavaScript] 4식 - Array  (0) 2020.07.12
[JavaScript] 2식 - Start JavaScript  (0) 2020.07.12
[JavaScript] 1식 - Why JS?  (0) 2020.07.12
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함