1. Variable, rw(read/write)

Mutable
- let( added in ES6 )

글로벌 스코프
let globalName = 'global name';

블록 스코프
    {
    let name = 'apple';
    console.log(name);
    }
    console.log(name); <- 호출 안됨
    console.log(globalName); // global name
  • var (don't ever use this!)
  • var hoisting (move declaration from bottom to top)
    변수가 어디에 선언 했는지 상관없이 항상 제일 위로 선언을 끌어 올려준다.
  • has no block scope

2. Constant, r(read only)

  • use const whenever passible.
  • only use let if variable needs to cahange.
const daysInWeek = 7;
const maxNumber = 5;
  • Immutable data types: primitive types, frozen objects (i.e. object.freeze()). 데이터 변경 불가
  • Mutable data types: all objects by default are mutable in JS. 데이터 변경 가능
  • favor immutable data type alwas for a few reasons:
    • security
    • thread safety
    • reduce human mistakes

3. Variable types

  • primitive: 값 자체가 메모리에 저장이 된다.

    • primitive, single item: number, string, boolean, null, undefined, symbol
  • Object: 오브젝트를 가리키는 레퍼런스가 메모리에 저장 된다.
    (레퍼런스에 통해서 실제로 오브젝트가 담겨 있는 메모리를 가리킨다)

    • object, box container
  • function, first-class function


출처: 드림코딩 by 엘리
링크텍스트

profile
코딩하는 아재입니다.

0개의 댓글

Powered by GraphCDN, the GraphQL CDN