💡 자바스크립트 변수 키워드, 상수, 데이터 타입, 블록 스코프, 글로벌 스코프, 타입 스크립트가 등장하게 된 이유에 대해서 공부해보자!

let name = 'yewon';
console.log(name); // yewon
name = 'hello';
console.log(name); // hello
console.log(age); // undefined
age = 4;
console.log(age); // 4
var age;
console.log(age);를 출력하면 undefined가 나오는 것을 볼 수 있다.'use strict';
console.log(age); // undefined
// 2. Variable, rw(read/write) 읽고 쓰는거 가능
// let (added in ES6)
let globalName = 'global name';
{ // block scope
let name = 'yewon';
console.log(name);
name = 'hello';
console.log(name);
console.log(globalName);
}
console.log(name);
console.log(globalName);
// var (don't ever use this!)
// var hoisting (move declaration from bottom to top)
age = 4;
var age;
console.log(age);
{
age = 4;
var age;
}
console.log(age); // 4
{ // block scope
let name = 'yewon';
console.log(name);
name = 'hello';
console.log(name);
}
console.log를 이용해 블록 밖에서 name이라는 변수에 접근하게 되면 아무값도 나오지 않는다.
global scope이라고 부른다.global scope은 어느 곳에서나 접근이 가능하다.let globalName = 'global name';
{ // block scope
let name = 'yewon';
console.log(name); // yewon
name = 'hello';
console.log(name); // hello
console.log(globalName); // global name
}
console.log(name); // 빈값 출력
console.log(globalName); // global name
const daysInWeek = 7;
const maxNumber = 5;
number, string, boolean, null, undefined, symbol

number type 하나면 끝~~number이라고 데이터 타입을 따로 선언도 안해도 된다.
const count = 17; // integer
const size = 17.1; // decimal number
console.log(`value: ${count}, type: ${typeof count}`);
console.log(`value: ${size}, type: ${typeof size}`);

number 하나면 끝~~
const infinity = 1/0; // infinity
const negativeInfinity = -1/0; // -infinity
const nAn = 'not a number'/2; // NaN
bigInt라는 타입이 추가가됨n만 붙이면 bigInt로 간주되어짐const bigInt = 1234567890123456789012345678901234567890n;
console.log(`value: ${bigInt}, type: ${typeof bigInt}`);

const char = 'c';
const brendan = 'brendan';
const greeting = 'hello' + brendan;
console.log(`value: ${greeting}, type: ${typeof greeting}`);
const helloBob = `hi ${brendan}!`; // template literals (string)
console.log(`value: ${helloBob}, type: ${typeof helloBob}`);

${} 를 이용하면 변수의 값도 자동적으로 출력 가능console.log('value: ' + helloBob + ' type: ' + typeof helloBob);
0, null, undefined, NaN, ''1, any other valueconst canRead = true;
const test = 3< 1; // false
console.log(`value: ${canRead}, type: ${typeof canRead}`);
console.log(`value: ${test}, type: ${typeof test}`);

let nothing = null;
console.log(`value: ${nothing}, type: ${typeof nothing}`);

let x;
// let x = undefined 라고 명확하게 할당해도 된다.
console.log(`value: ${x}, type: ${typeof x}`);

const symbol1 = Symbol('id');
const symbol2 = Symbol('id');
console.log(symbol1 === symbol2); // false
id를 이용하여 Symbol를 만들었지만, 이 2가지의 Symbol은 다른 경우이다.const gSymbol1 = Symbol.for('id');
const gSymbol2 = Symbol.for('id');
console.log(gSymbol1 === gSymbol2); // true
.for을 추가해서 적어주면 된다.console.log(`value: ${symbol1}, type: ${typeof symbol1}`); // error
console.log(`value: ${symbol1.description}, type: ${typeof symbol1}`);

.description을 추가해서 string으로 변환한 다음에 출력해야한다.const yewon = {name: 'yewon', age: '25'};
age는 아무것도 설명이 되지 않지만 -> yewon이라는 object를 만들어서 name: 'yewon', age: '25' 이름은 yewon이고, 나이는 25 이다. 라고 설명할 수 있다.yewon은 const 키워드로 정의되어 있기 때문에 다른 오브젝트로 할당 불가yewon object 안에는 name, age라는 변수들이 존재yewon.age = 26;
Dynamically-Typed Language라고 불린다.Statically-Typed Language라고 불린다.Dynamic typing 언어는 내가 좋은 아이디어가 있을 때, 빠르게 프로토타이핑을 할 때는 굉장히 유용let text = 'hello';
console.log(`value: ${text}, type: ${typeof text}`);
text = 1;
console.log(`value: ${text}, type: ${typeof text}`);
text = '7' + 5;
console.log(`value: ${text}, type: ${typeof text}`);
text = '8' / '2';
console.log(`value: ${text}, type: ${typeof text}`);

let text = 'hello';
console.log(text.charAt(0)); // h 출력
console.log(`value: ${text}, type: ${typeof text}`);
text = 1;
console.log(`value: ${text}, type: ${typeof text}`);
text = '7' + 5;
console.log(`value: ${text}, type: ${typeof text}`);
// 누군가가 타입을 바꿔버리면?
text = '8' / '2';
console.log(text.charAt(0)); // error 발생
console.log(`value: ${text}, type: ${typeof text}`);
dynamically typed 때문에 고생을 많이해서 TypeScript가 등장하게 된 것➕ 추가로 공부할 것
1. template literals 찾아보기
2. first-class function(일급함수)에 대해서 공부하기
3. hoisting에 대해서 공부하기
4. TransCompiler(babel)에 대해 찾아보기
5. symbol 타입에 대해서 더 공부하기