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
- Filter
- array
- supabase 페이지네이션
- app.post
- code-push-standalone
- set
- Spring
- map
- Next.js
- 글또10기x코드트리
- 코드푸시
- javascript
- 상속
- supabase auth
- TS
- 타입스크립트
- 페이지네이션
- supabase authentication
- 슬라이딩윈도우
- react
- generic
- xlsx-js-style
- async
- interface
- reactnative
- extends
- codepush
- meatadata
- 이진탐색
- 스크롤이벤트
Archives
- Today
- Total
rhanziy
javascript. 함수 function 본문
function changeName(obj) {
obj.name = 'coder';
}
const rhanyi = { name: 'rhanyi' };
changeName(rhanyi);
console.log(rhanyi);
function showMessage(message, from = 'unknown') {
console.log(`${message} by ${from}`);
}
showMessage('hi');
function printAll(...args) {
// 아래 세개는 같은 결과값.
for (let i = 0; i < args.length; i++){
console.log(args[i]);
}
for(const arg of args) {
console.log(arg);
}
args.forEach((arg) => console.log(arg));
}
printAll('dream', 'coding', 'rhanyi');
function upgradeUser(user) {
if (user.point > 10) {
// ...logic
}
} // -> bad
function upgradeUser(user){
if (user.point <= 10) {
return;
}
// ...logic
} // -> early return, early exit good
const print = function( ) { // 익명함수
console.log('print');
}
print( );
const printAgain = print;
printAgain( );
// 함수도 호이스팅이 된다.
//------------------콜백함수 기본-------------------//
// 함수의 파라미터로 함수를 받는다.
function randomQuiz(answer, printYes, printNo) {
if ( answer === 'love you' ) {
printYes( );
} else { printNo( ); }
}
const printYes = function( ){
console.log('yes!');
}
const printNo = function print( ){
console.log('no!');
}
randomQuiz('wrong', printYes, printNo);
randomQuiz('love you', printYes, printNo);
// Arrow function
// const simplePrint = function( ) {
// console.log('simplePrint');
// }
const simplePrint = ( ) => console.log('simplePrint');
const add = (a, b) => a + b ;
// IIFE : Immediately Invoked Function Expression 선언함과 동시에 함수호출
(function hello( ) {
console.log('IIFE');
})( );
//Quiz
function calculate(command, a, b) {
switch (command) {
case 'add':
return a+b;
case 'substract':
return a-b;
case 'divide':
return a/b;
case 'multiply':
return a*b;
case 'remainder':
return a%b;
default:
throw Error('unknown command');
}
}
console.log(calculate('add', 2, 3));
'Html_css_js' 카테고리의 다른 글
javascript. class (0) | 2022.01.19 |
---|---|
js. 문서의 맨 끝에 스크롤 도달 시 이벤트 실행 (0) | 2022.01.18 |
js. 스크롤 한 높이값 만큼 컨텐츠 position 이동하기 (0) | 2022.01.17 |
javascript. 연산자, 반복문 (0) | 2022.01.17 |
javascript. script태그 async 와 defer의 차이점 (0) | 2022.01.16 |
Comments