250x250
Notice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- httpURLConnection
- 리눅스폴더권한설정
- 쉐퍼드역
- 앱과 php 통신
- 리눅스폴더삭제
- 앱 서버통신
- 리눅스폴더생성
- 안드로이드
- 앱
- 리버사이드호텔후기
- restapi
- 리눅스폴더바꾸기
- 리눅스파일생성
- 리버사이드결혼식
- 리버사이드뷔페
- 리버사이드신사역
- 안드로이드 다시시작
- 결혼식장소추천
- 신사역결혼식
- 강남결혼식
- 리눅스디렉토리
- 우분투문법
- 앱http
- RETROFIT
- 리버사이드호텔
- 폴더권한
- 리눅스
- 리버사이드피로연
- 리눅스문법
- 앱서버
Archives
Alice In Toronto
5. Arrow Function은 무엇인가? 함수의 선언과 표현 본문
728x90
** 이 글은 유튜브 강의을 보고 공부하면서 스스로 콘솔로 작성하고, 따라치면서 Javascript 기초 공부를 하는 공간입니다.
www.youtube.com/watch?v=e_lU39U-5bQ&list=PLv2d7VI9OotTVOL4QmPfvJWPJvkmv6h-2&index=5
// Function
// - fundamental building block in the program
// - subprogram can be used multiple times
// - performs a task or calculates a value
// 1. Function decalration
// function name(param1, param2) { body... return;}
// one function === one thing
// naming: doSomething, command, verb
// eg. createCardAndPoint -> createCard, createPoint
// functuib is object in JS
function printHello(){
console.log('Hello');
}
printHello();
function log(message) {
console.log(message);
}
log("1234");
log(1234);
//2, Parameters
// premitive parameters: passed by value
// object parameters: passed by reference
function changename(obj){
obj.name = "alice";
}
const ellie = { name: 'ellie'};
changename(ellie);
console.log(ellie);
//3. Default parameters ( added in ES6 )
function showmessage(message, from = 'unknown') {
console.log('${message} by ${from}'); //Hi by unknown
}
showmessage('Hi!');
//4. Rest parameters ( added in ES6 )
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', 'ellie');
// 5. Local scope
let globalMessage = 'global';
function printMessage(){
let message = 'hello';
console.log(message);
console.log(globalMessage);
function printAnother(){
console.log(message);
let childMessage = 'hello';
}
console.log(childMessage); //error!!!!!!!!!!!!!!!!!!!!!
}
printMessage();
//6. Return a value
function sum(a,b) {
return a+b;
}
const sum = sum(5,4);
console.log('5+4 is ${sum(5,4)}');
//7. Early return, early exit
// bad
function updgradeUser(user){
if(user.point > 10){
// Long upgrade logic .......
}
}
//good
function upgradeUaseer(user) {
if(user.point < 10){
return;
}
// Long upgrade logic .......
}
// First-class Function
// functions are treated like any other variable
// can be assigend as a value to variable
// can be passed as an argument to other functions
// can be returned by another function
//1. Function expression
// a function decalration can be called earlier than it is defined (hoisted)
// a functuib expression is created when the execution reches it.
const print = function (){
consile.log('print');
}
print();
const printAgain = print;
printAgain();
const sumAgain = sum;
console.log(sumAgain(1,3));
//2. Callback function using function expression
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);
// Arrow Function
// always anonymous
const simplePrint = function (){
console.log('simpleprint!');
};
const simplePrint = () => console.log('simpleprint!');
const add = (a,b) => a + b; // return a+b;
// IIFE : Immediately Invoked Function Expression
function hello(){
console.log('IIFE!');
}
// 바로 호출하고 싶은경우 !!!!!!!!!!!!!!!
(function hello(){
console.log('IIFE!');
})();
728x90
'개발공부 > Javascript' 카테고리의 다른 글
8. 배열 제대로 알고 쓰자. 자바스크립트 배열 개념과 APIs 총정리 (0) | 2021.04.27 |
---|---|
7. 오브젝트 넌 뭐니? (0) | 2021.04.27 |
6. 클래스와 오브젝트의 차이점(class vs object), 객체지향 언어 클래스 정리 (0) | 2021.04.27 |
4. 코딩의 기본 operator, if, for loop 코드리뷰 팁 (0) | 2021.04.27 |
3. 데이터타입, data types, let vs var, hoisting (0) | 2021.04.27 |
Comments