string → 문자(char), 문자열(string)
const str = "string"
const str2 = 'string'
const str3 = `string ${str}` -> ES6
number → 숫자 (int : 정수, float : 실수)
const int = 10 // 정수
const float = 1.2 // 실수
"10" + 1 // 101
parseInt("10") + 1 // 11
parseInt("1.1") // 1
parseFloat("1.1") + 1 // 2.1
boolean → 참, 거짓 (true, false)
- 가장 많이 쓴다.
- false 대체하는 ? null, undefined, 0, ""
- 부정의 부정은 긍정이다. !!false
undefined
const a;
console.log(a) // undefined
확인이 안될때. 찾지못할 때 변수에 값을 설정하지 않았을때 비어있다. 라는 의미
null
변수에 직접 설정해줬을때만 확인할 수 있다.
비어있다. 라는 의미
array → 배열 (반복 iterator, loop)
const arr = [1,2,3,4,5] // 색인 : Index
arr[0] // 1 -> 0번째 index
arr[4] = 6 // [1,2,3,4,6]
const arr2 = [1, "Jhon"] (X) // 배열안에 들어가는 아이템 타입은 통일 시켜주는게 좋다.
object → 객체 ( 중괄호로 표현한다. { key: value } )
const obj = {
key: "value",
key1: 3,
key2: function () {}
}
함수 → function()