프로그래밍 - 입력 연산 출력
read, write 가능
-변경될 수 있는 값 (mutable data type)
let name = 'sshu'
name = 'hello'
block scope : { } 블록 안의 변수는 블록 안에서만 활동
{
let name = 'sshu'
name = 'hello'
}
global scope : 전역에 선언한 변수는 전체에서 활동 (최소화해야함)
var (before ES6 : Don't ever use this)
hoisting되어 선언 전에도 쓸 수 있는 뒤죽박죽 상황이 초래
block scope 개념이 없어서 규모있는 프로젝트에 안좋음
ES6 (인터넷 익스플로러에서 제공 X) 로 작성하고 최종 배포때 babel로 컴파일하여 ES4로 배포. (아니면 익스플로러 무시)
read만 가능
-변하지 않는 값 (Immutable data type)
-보안상의 이유 security
-맥락들이 동시에 변수에 접근할 경우 thread safety
-변경될 이유없다면 무조건 const
: single item 더이상 작게 나눌 수 없는 데이터 타입
number, string, boolean, null, undefined, symbol..
정수 integer
소숫점 숫자 decimal number
예) const number= 324890280482903489023589709n
문자열
template literal : `hi ${variables}`
참거짓
false: 0, null, undefined, NaN, ' '
true: any other value
const canRead = true;
const test = 3<1 (false)
개발자가 빈값이라고 지정해줄 때 사용
값이 할당되지 않은 상태
맵이나 자료구조에서 고유의 값이 필요할 때
동시다발적 코드에서 우선순위가 필요할 때
const symbol1 = Symbol('id')
const symbol2 = Symbol('id')
symbol1 === symbol2 (false)
const gSymbol1 = symbole.for('id')
const gSymbol2 = symbole.for('id')
gSymbol1 === gSymbol2 (true)
변수가 선언될 때 타입이 결정됨.
let text = 'hello'
text = '7'+5 문자와 숫자를 더하면 문자가되고
text = '8' / '5' 문자 두개를 나누면 숫자가 됨..
runtime error 발생이 심각...
⇒ type script 가 탄생.
: single item들을 여러개 묶어서 한 단위로 관리가능한 데이터 타입
→ 값이 커서 레퍼런스만을 저장 (각 개별 밸류를 변경할 수 있는 이유)
const sshu = {name:'sshu', age:30}
sshu.age = 31;
: first class function 함수를 변수에 할당 가능
함수의 인자나 리턴값을 함수로 가능.