Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- node.js
- localStorage
- Partition
- mariadb
- EventSource
- 성장기
- Lag
- ServerSentEvent
- 개발자
- SSE
- partitioning
- Node.js기본
- 실시간알림
- node.js란
- 파티셔닝
- frontend
- 열공하자
- PostgreSQL
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[JavaScript][Ch9] JS 함수 본문
함수
특정 동작(기능)을 수행하는 일부 코드의 집합(부분)
function
// 함수 선언
function helloFunc() {
// 실행 코드
console.log(1234);
}
// 함수 호출
helloFunc(); // 1234
함수 안에서 특정값을 반환할 수 있다. -> return 사용
function returnFunc() {
return 123; // 123을 반환해줌
}
let a = returnFunc();
console.log(a); // 123
매개변수와 인수
function sum(a, b) { // a, b는 매개변수(Parameters)
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();
world();
객체 데이터
// 객체 데이터
const searchkim = {
name: 'SEARCHKIM',
age: 85,
// getName에 익명함수가 데이터로써 들어가있음(함수의 표현)
// 속성에 함수가 할당되어 있으면 메소드라고 함
getName: function () { // 메소드(Method)
return this.name;
}
};
const name = searchkim.getName();
console.log(name); // SEARCHKIM
console.log(searchkim.getName()); // SEARCHKIM
'파도파도 나오는 JavaScript' 카테고리의 다른 글
[JavaScript][Ch9] JS DOM API (0) | 2022.01.06 |
---|---|
[JavaScript][Ch9] JS 조건문 (0) | 2022.01.06 |
[JavaScript][Ch9] JS 변수, 예약어 (0) | 2022.01.05 |
[JavaScript][Ch9] JS 데이터 종류 (0) | 2022.01.05 |
[JavaScript][Ch9] JS 개요 (0) | 2022.01.05 |
Comments