String
- 하나의 문서에서 따옴표를 일관적으로 사용해야함
"String"or'String'
- 문자열 접근
index[0]~index[n-1]
- 문자열 길이
str.length
- 문자열 결합
- “str”
+“ing”
- “str”
- escape character
- \
- as an object
- new ( not recommended, 속도 저하)
let x = "kiwi"; //literals;
let y = new String("kiwi"); // object
let z = (x==y); //true
let z = (x===y); //false
comparing two JS objects always return **false
Template Literal
- concat 대체, 편의성 향상
`hi my name is ${expressions}.`
Number
- Always one type (double, 64bit)
- Exponential Notation ( 너무 크거나 너무 작은 숫자를 편하게 작성하는 방법)
let y = 123e5; //12300000 let z = 123e-5; //0.00123
Bigint
- ES2020~
let x = BigInt("12345678901234567890");
Boolean
let x = 5; let y = 5; let z = 6; (x==y) //true (x==z) //false
number로 type 전환 가능
Undefined
- Not assigned
Null
- assigned, but value is none
let str = ""; //typeof(str)=string
Symbol
- 변경 불가능한 원시 값
- 일반적으로 객체의 프로퍼티 키로 사용
- new 연산자를 이용한 래퍼 객체의 생성 불가능
const sy = new Symbol(); //Type Error
const sy1 = Symbol();
const sy2 = Symbol();
console.log(sy1===sy2); //false
Object
const color = {red : "apple", yellow : "banana"};
- pair of (name:values)
- access to object properties
- objectName.propertyName;
- objectName[“propertyName”];
- access to object properties
Array
- 순서가 있는 집합
- 다른 타입도 한 배열에 정렬 가능
let array = []; let mixdArray = [true, 42, "aaa", null]; - 값 변경 및 추가 가능
- 참조를 바꾸거나 재할당 할 수는 없지만 내부 컨텐츠는 바뀔 수 있음
- 각 변수는 참조 주소 값을 가지므로 값을 기준으로 비교 하지 않음
const arr1 = [1, 2, 3];
const arr2 = [1, 2, 3];
arr1 === arr2 //false
date
const date = new Date("2023-12-31");