typescript
[Typescript] 기본타입1(number, string, boolean, undefined, null)
슬래기
2022. 6. 16. 19:11
Javascript의 타입에는
primetive : number ,string, boolean, bigint, null, undefined
Object : function, array...
이렇게 존재한다.
Typescript의 기본타입인 number, string, boolean, undefined, null 을 알아보자.
숫자 : Number
숫자 입력값이다. 소숫점, -도 포함하여 사용하면 된다.
//number
const num:number = 1;
문자 : String
문자값이다. 기본적인 string값이라고 생각하면 된다.
//string
const str:string ='hello';
불리언 : Boolean
참/거짓(true/false) 값을 나타낸다.
//boolean
const boal:boolean=false;
null 과 undefined
보통 union( | )과 같이 쓰인다. 유니온이란 | 기호로 or조건으로 받아들이면 될것같다.
//undefined 숫자 또는 undefined 보편적으로는 많이 이용.
let age : number | undefined = undefined;
age = 1;
//예를 들어 함수에서 많이 사용한다.
function find() : number | undefined{
return undefined;
}
//null
let person2 : string | null;