ungju 님의 블로그

[Typescript] 원시 타입 본문

typescript

[Typescript] 원시 타입

ungju 2025. 2. 24. 00:41
반응형

🔹 원시 타입 (Primitive Types)

원시 타입은 값이 변경되지 않는 기본적인 타입이다.

값이 변경되지 않는 기본적인 타입
• number, string, boolean
• null, undefined
• bigint, symbol (이 글에선 제외)


1. 문자 타입 (String Type)

string으로 표현한다.

const dog: string = "우리집 막내는 연지다.";

2. 숫자 타입 (Number Type)

number로 표현한다.

const dogAge: number = 13;

3. 불리언 타입 (Boolean Type)

참/거짓(true/false) 값이며, boolean으로 표현한다.

const isFamily: boolean = true;

4. null 타입, undefined 타입

// null
const box1: null = null;

// undefined
const box2: undefined = undefined;

5. 리터럴 타입 (Literal Type)

리터럴 타입은 하나의 값만 가지는 타입이다.
리터럴 타입은 미리 정의된 값만 가질 수 있도록 제한하는 타입이다.

// 타입이 'yeonji'라는 문자이기 때문에 'yeonji'만 할당 가능함. 
const name: "yeonji" = "yeonji";

// 타입이 true이기 때문에 true 값만 할당 가능함. 
const isCute: true = true;

'typescript' 카테고리의 다른 글

[Typescript] 객체 타입  (2) 2025.03.29
[Typescript] 타입 종류  (2) 2025.02.23