1. primitive, single item => number, string, boolean, null, undefined, symbol
2. object, box container
3. function, first-class function
※ Variable(var,let) read/write
Constant(const) read only
※변환불가능 Immutable data types : premitive types, froxen objects
※변환 가능 Mutable data types : all objects by default are mutable in JS
ex)배열도 변환 가능!
1) number 선언 안해도 가능
ex. count = 17;
연산 시 기억해야 할 3가지
1. const infinity = 1/0; → Infinity
2. const negativeInfinity = -1/0; → -Infinity
3. const NaN = 'not a number' / 2; → NaN
※NaN: not a number
(+)const bigInt = 12334543n; 끝에 n 붙이기
2) String 타입
const char = 'c';
const brendan = 'brendan';
const greeting = 'hello' + brendan;
console.log(`value: ${greeting}, type: ${typeof greeing}`);
const helloBob = `hi ${helloBob}, type: ${typeof helloBob}`);
[ = console.log('value: ' + helloBob + ' type: ' typeof helloBob); ]
`를 사용하면 중간에 +넣을 필요없이 변수 넣을 수 있음
3) boolean
//false: 0, null, undefined, NaN(not a number)
//true: any other value
const canRead = true;
const test = 3 < 1; // false
console.log(`value: ${canRead}, type: ${typeof canRead}`); -> value: true, type: boolean
console.log(`value: ${test}, type: ${typeof test}`); -> value: false, type: boolean
4) null
let nothing = null;
console.log(`value: ${nothing}, type: ${typeof nothing}`); -> value: null, type: object
5) undefined:선언은 되었지만 아무것도 값이 지정되어 있지 않음
let x;
let x = undefined; 둘 다 가능
console.log(`value: ${x}, type: ${typeof x}`); -> value: undefined, undefined
6) symbol : create unique identifiers for objects
const symbol1 = Symbol('id');
const symbol2 = Symbol('id');
console.log(symbol1 === symbol2); → false
정말 고유한 식별자가 필요할 때 사용함, 문자형식일 경우 위의 두 symbol은 다름
똑같이 만들고 싶다면
const gSymbol1 = Symbol.for('id'); 이렇게 씀
그리고 항상 바로 출력이 아니라 .description 해야함!
console.log(`value: ${symbol1.description}
================================================================
**JavaScript는 Dynimic typing: dynamically typed language입니다. 즉 runtime 시 type이 정해집니다.**
let text = 'hello';
console.log(`value: ${text}, type: ${typeof test}`);
→ value: hello , type: string
text = 1;
console.log(`value: ${text}, type: ${typeof text}`);
→ value: 1, type: number
text = '7' + 5;
console.log(`value: ${text}, type: ${typeof text}`);
→ value:75, type: string
text = '8' / '2'
console.log(`value: ${text}, type: ${typeof text}`);
→ value: 4, type: number
'JavaScript > 엘리 JavaScript note' 카테고리의 다른 글
| Part 8 <Array 개념과 APIs> (0) | 2021.12.26 |
|---|---|
| Part 7 <Object> (0) | 2021.12.26 |
| Part 6 <Class vs Object> (0) | 2021.12.26 |
| Part 5 <Functions 함수> (0) | 2021.12.26 |
| Part 4 <연산, 반복문> (0) | 2021.12.25 |