티스토리 뷰
1. let vs var, hoisting
- Variable, rw(read/write)
- let (added in ES6)
- scope
- global scope
- block scope
Var
- var (don't ever ues this)
- var hoisting (move declaration from bottom to top)
- has no block scope
- block scope ignore
Constant, r (read only)
- favor immutable data type always for a few reasons
- security
- thread safety
- reduce human mistakes
2. data types
Variable types
- primitive, single item
- number
- string
- boolean
- null
- undefined
- symbol
- object
- box container
- function
- first-class function
| Note !
- immutable data types
- primitive types
- frozen objects (i.e.object.freeze())
- mutable data types
- all objects by default are mutable in JS
number
const count = 17; // integer
const size = 17.1; // decimal number
console.log(`value: ${count}, type: ${typeof count}`); // 17, number
console.log(`value: ${size}, type: ${typeof size}`); // 17.1 number
- number - special numeric values : infinity, -infinity, NaN
const infinity = 1 / 0;
const negativeInfinity = -1 / 0;
const nAn = 'not a number' / 2;
console.log(infinity); // Infinity
console.log(negativeInfinity); // -Infinity
console.log(nAn); // NaN
- bigInt (fairly new, don't use it yet)
const bigInt = 123456678012345667891234566789123456767890n; // over (-2*53) ~ 2*53
console.log(`value: ${bigInt}, type: ${typeof bigInt}`);
Number.MAX_SAFE_INTEGER;
string
const char = 'c';
const brendan = 'brendan';
const greeting = 'hello ' + brendan;
console.log(`value: ${greeting}, type: ${typeof greeting}`); // string
const helloBob = `hi ${brendan}!`; // template literals (string)
console.log(`value: ${helloBob}, type: ${typeof helloBob}`); // string
boolean
- false
- 0
- null
- undefined
- NaN
- ""
- true
- any other value
const canRead = true;
const test = 3 < 1; // false
console.log(`value: ${canRead}, type: ${typeof canRead}`); // boolean
console.log(`value: ${test }, type: ${typeof test }`); // boolean
null
let nothing = null;
console.log(`value: ${nothing}, type: ${typeof nothing}`); // null
undefined
let x;
console.log(`value: ${x}, type: ${typeof x}`); // undefined
symbol
- symbol, create unique identifiers for objects
const symbol1 = Symbol('id');
const symbol2 = Symbol('id');
console.log(symbol1 === symbol2) // false
const gSymbol1 = Symbol.for('id');
const gSymbol2 = Symbol.for('id');
console.log(gSymbol1 === gSymbol2 ) // true
console.log(`value: ${symbol1.description}`); // id
object, real-life object, data structure
const ellie = { name: 'ellie', age: 20 };
ellie.age = 21;
Dynamic typing : dynamically typed language
let text = 'hello';
console.log(text.charAt(0)); // h
console.log(`value: ${text}, type: ${typeof text}`); // hello, string
text = 1;
console.log(`value: ${text}, type: ${typeof text}`); // 1, number
text = '7' + 5;
console.log(`value: ${text}, type: ${typeof text}`); // 75, string
text = '8' / '2';
console.log(`value: ${text}, type: ${typeof text}`); // 4, number
※출처
'JavaScript & TypeScript' 카테고리의 다른 글
6. what is object (0) | 2020.11.14 |
---|---|
5. class vs object (0) | 2020.11.14 |
4. Arrow Function (0) | 2020.11.13 |
3. operator, if, for loop (0) | 2020.11.13 |
1. script async vs defer (0) | 2020.11.13 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 김영한 http
- dreamcoding
- 모던자바스크립트
- Spring Security
- 프로그래머스
- 이펙티브자바 아이템60
- 프로그래머스 SQL
- js promise
- 드림코딩
- java
- 이펙티브자바 아이템59
- HTTP 완벽가이드
- JPA 연관관계 매핑
- 이펙티브자바 스터디
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- js array
- 김영한 JPA
- JS 딥다이브
- 이펙티브자바
- HTTP 완벽 가이드
- js api
- 백준
- BOJ
- http
- REST API
- GCP
- 패스트캠퍼스 컴퓨터공학 완주반
- ㅇㄷㅇㅈ
- 백기선 스터디
- 킹수빈닷컴
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함