Variable(변수)와 Hoisting

유호익·2021년 1월 2일
0

js

목록 보기
2/3

1. Variable (Mutable data type)

let (added in ES6)
Block scope
{}
변수는 Block scope 안에서 선언하되
Global scope은 Block 밖에서 선언한다
블록안에서 선언한 변수는 블록밖에서 보이지 않는다

Global scope은 촤소한으로 쓰자

var // dont ever use this!
var hoisting - 선언한 위치와 상관없이 선언을 맨위로 끌어 올려주는 현상
var 는 블록도 무시하기 때문에 let으로 선언하도록 하자

2. constant (Immutable data type)

  • security
  • thread safety
  • reduce human mistakes

3. Variable types

1) primitive, single item: number, string, boolean, null, undefiend, symbol
2) object, box container
3) function, first-class function

  • number - special numeric values: infinity, -infinity, Nan(not a numver)

  • string
    const greeting = 'hello ' + name;
    기본 - console.log(greeting + 'good to see you');
    template literals - console.log(백틱${greeting}, good to see you백틱)

  • boolean
    false:0, null, undefiend, nan, ''
    true: any other value

  • null
    값이 없다고 명확하게 선언

  • undefined
    값이 지정되지 않음

  • symbol
    creat unique identifiers for objects
    고유의 값으로 같은 symbol 값을 주고 싶다면
    const symbol1 = symbol.for('id');
    const symbol2 = symbol.for('id');
    console.log(symbol1 === symbol2); -> true
    symbol값을 출력하고 싶다면 string으로 변환해서 출력해준다
    symbol1.description

  • Immutable data types : primitive types, frozen object (i.e. object.freeze())
  • Mutable data types : all objects by default are mutable in JS

4. Dynamic typing

연산에 의해서 data type이 변경됨

profile
There's more to do than can ever be done

0개의 댓글