Java Script 정리

원종서·2021년 7월 13일
0

variable

let (added in ES6)

var

1 hoisting : 어디에 선언한지 상관없이 선언을 맨 위로 올려준다.
2 block scope 없다. 지역 변수 , 전역변수 그런 거 없음..

variable tpye

primitive (더 이상 나눠질 수 없는 단위, single itemm): number , string , boolean, null, nudefined simbol

first-class function 이란 function을 값에 대입할 수 있음

operator

const srtingFive = "5";
const numberFice = 5;

if(srtingFive == numberFice); // 타입을 자동적으로 변경해서 검사함 -> true
if(srtingFive === numberFice); // 타입 변경 없음 -> false

Object

one of the js'data types
a collection of related data and/or funcionality.
Nearly all obejct in JS are instance of Object

const obj1 = {}; // 'object literal' syntax
const obj2 = new Object(); //'object construcor' syntax

const jong = {name: "jnog ", age: 25};
jong.hasJob = true; // Can add props 
delete jong.hasJob;// Can delete props.

//for..in vs for..of
//for(key in obj) // 오브젝트안에 있는 키들을 확인
//for(value of array)

Array APIs


fruits = ["apple", "banana"];

// forEach
fruits.forEach((fruit) => {
   console.log(fruit);
});

//add = push
//delete == pop

//unshift = add an item to the beginning

fruits.unshift("orange");

//shift = remove an item to the beginning

fruits.shift();

//splice : remove an item by index postion

fruits.splice(); // 지우기 시작할 인덱스, 몇개를 지울건지, 추가할 원소

//combine two array
const fruits2 = ["kiwi", "mango"];
const newFruit = fruits.concat(fruits2);


//find the index
//array.indexOf()

//comfrim the index
// array.includes():boolean

Promise

"use strict";

// promise is a Js object for asynchronous operation.

//1 . state : pending -> fulfilled or rejected
//2 produder vs consumer

//1. producer

//when new Promise is created , the executor runs automatically.
const promise = new Promise((resolve, reject) => {
    console.log("doing something..");
    setTimeout(() => {
        resolve("jong");
        // reject(new Error("no network"));
    }, 2000);
}); // 

//2. Consumer, then, catch, finally;

promise //
    .then((value) => {
        console.log(value);
    })
    .catch((error) => {
        console.log(error);
    })
    .finally(() => {
        console.log("finally");
    });

0개의 댓글