WEB/javaScript
[javaScript/공부] 자료형
ijooha
2024. 12. 12. 19:54
숫자형(Number)
1234567890
NaN
일반적인 숫자 (123..)가 있고,
아래와 같은 특수 숫자 값(special numeric value)가 있다.
infinity | 무한대 (0으로 나누거나, 직접 참조) |
NaN | 숫자가 아님(Not a Number) |
문자형(String)
"hello"
'hello'
`hello`
역따옴표로 변수나 표현식을 감싼 후 ${}를 넣어주면, 원하는 데이터를 넣을 수 있다.
let name = "Amy";
alert(`hello, ${name}`);//hello, Amy
alert (`the result is ${1+2}`);//the result is 3
불린형(Boolean)
true 참
false 거짓
Null & Undefined
Null
존재하지 않는 값, 알 수 없는 값
Undefined
변수에 값이 할당되지 않았을 때 할당되는 값
실재로 변수에 'undefined'를 할당할 수도 있지만, 권장하지 않음
값이 없을 때는 'null'을 할당
typeof
typeof()
괄호는 생략이 가능하다.
변수의 자료형을 반환한다.
typeof 1 //"number"
typeof "hello" //"string"
null
Math
** null과 내장객체는 "object"객체형임
함수는 "function", 객체형에 속하지만 이렇게 표기됨