본문 바로가기
TypeScript

TypeScript - 기초 문법

by J-non 2024. 4. 30.

<목차>

1. typescript란?

2. typescript 기초 문법

 


1. typescript란?

typescript는 javascript의 슈퍼셋(상위 확장)으로 javascript에서 타입 검사가 추가된 확장 언이다.

질문사항

typescript는 javascript와 다르게 런타임 환경이 존재하지 않는다. nodejs에서 javascript로 트랜스파일 한다.
typescript -> node.js를 통한 트랜스파일 -> javascript 순으로 작동한다.

 


2. typescript 기초 문법

typescript는 javascript에 type검사를 추가하기 위해 만들어졌다.

 

문법

[예약어] [변수이름] : [타입] = [값]

// 원시타입
let num: number = 1;

let str: string = "문자열";

let bool: boolean = true;

// 참조타입
// 함수는 매개변수의 타입과 반환값의 타입을 지정해 주어야 한다.
function fn(num:number):void {}

let arr: any[] = ["문자열", 1, true];