[드림코딩 JS 마스터리] 원시값(number, string, boolean, empty)

Jessie H·2022년 5월 15일
0
post-thumbnail

png created by here

자바스크립트의 데이터 종류는 크게 Primitive, Object 두개로 나눌 수 있다.



Primitive 원시값

relating to, denoting, or preserving the character of an early stage in the evolutionary or historical development of something.

어떤 것의 역사적인 발전 과정 중에서 최초 단계에 해당하는 것, 그 특징

원시값은 number, string, boolean, empty, Symbol이 있다.



number 숫자

999, -999, 9.99 따로 숫자의 종류를 선언할 필요는 없다.
2진수, 8진수, 16진수도 가능

0/정수 = 0
정수/0 = Infinity(무한)
정수/-0 = -Infinity
999/'abc' = NaN(Not a Number)



string 문자 또는 문자열

  • "" 또는 '' 또는 ``로 표현 가능
    ``로 표현할 경우 줄바꿈도 따로 표현하지 않아도 됨(템플릿 리터럴)
let myfruit = 'apple';
let fruit = `My fruit is apple!`
  • \n줄바꿈
    \t tab
let dinner = '오늘 \n\t저녁은 \n 마라탕이다!';
console.log(dinner);
//오늘 
//	저녁은
// 마라탕이다!
  • ""를 표현할 때는 ''로 감싸기
let eat = "'먹자'";
console.log(eat);

\(백슬러시) 뒤에는 특수문자 쓸 수 있음
\자체를 출력하려면 백슬러시 두번 쓸 것

console.log(\/\\\_\/\\);
// /\_/\


boolean

true or false


falshy 거짓인 값

0
-0
""
null
undefined
NaN

truthy 참인 값

1
-1
"문자"
{}
Infinity



empty

null 또는 undefined

undefined = 활성화된 값이 있는지 없는지 모르는 상태
null = 활성화된 값이 없는 상태

undefined는 상자 안에 무엇이 있긴 한건지 아예 아무것도 없는건지 조차 모르는 상태
null은 상자 안에 아무것도 안들어있다는 걸 아는 상태
에 비유해볼 수 있다.

변수 정의 시 아무것도 적지 않으면 undefined 상태가 된다

profile
코딩 공부 기록장

0개의 댓글