[TypeScript] TypeScript Grammar - 01

2023. 1. 7. 21:37·Development Study/Frontend
728x90


1.  Type Annotation

TypeScript uses colon ( : ) behind variables to annotate a type

const myMaxHamburger: number = 3;
const answer: string = "Yes I can";
const drinks: boolean = true;

You can code like variable: <type>

It is essential to write this annotation, so be careful to pass by this


1_01.  Type Declaration_string

let str: string;
let red: string = 'Red';
let green: string = 'Green';
let myColor: string = `Do you like Color ${green}?`;

You can code like let <variable name>: <type>  

String type is just a letter that can't be calculated


1_02.  Type Declaration_number

let num: number;
let integer: number = 6;
let float: number = 3.14;
let hex: number = NaN;

In Java, you can't use integers as float. But in Typescript, we can use them equally


1_03.  Type Declaration_union type

let name: string | number = 'john';
let name: string | number = 123;
let name: string[] | number = ['test1', 'test2', 'test3'];

 

You can grammarly understand this as "You can use either A or B"

For example, we can call the name either string or number.

Therefore, it can be more flexible


1_04.  Type Declaration_boolean

let isBool: boolean;
let isDone: boolean = false;

const size: number = 101;
const isHuge: boolean = size >= 99; // <- this area return as boolean type

 


End

 

 

Next Series

 

[TypeScript] TypeScript Grammar - 02

Previous Series [TypeScript] TypeScript Grammar - 01 1. Type Annotation TypeScript uses colon ( : ) behind variables to annotate a type const myMaxHamburger: number = 3; const answer: string = "Yes I can"; const drinks: boolean = true; You can code like va

time-map-installer.tistory.com

 

728x90
저작자표시 비영리 변경금지 (새창열림)

'Development Study > Frontend' 카테고리의 다른 글

[TypeScript] TypeScript Grammar - 03~05  (0) 2023.01.07
[TypeScript] TypeScript Grammar - 02  (0) 2023.01.07
[TypeScript] Differences between .ts & .tsx  (0) 2023.01.07
[배경지식] CSS 프레임워크를 알아보자  (1) 2022.12.31
[배경지식] JavaScript? TypeScript? 이 둘의 차이는 무엇일까?  (0) 2022.12.31
'Development Study/Frontend' 카테고리의 다른 글
  • [TypeScript] TypeScript Grammar - 03~05
  • [TypeScript] TypeScript Grammar - 02
  • [TypeScript] Differences between .ts & .tsx
  • [배경지식] CSS 프레임워크를 알아보자
ThreeLight
ThreeLight
ThreeLight Studio의 블로그, TimeMap.exe에 오신 것을 환영합니다.
  • ThreeLight
    TimeMap.exe
    ThreeLight
  • 전체
    오늘
    어제
    • 분류 전체보기 (245)
      • Checkpoint (1)
      • (3D)Dev Deep Dive (0)
        • Templates & Guides (9)
        • Frontend origin (9)
        • Backend origin (1)
        • TroubleShootings (4)
      • Development Study (95)
        • Frontend (36)
        • Backend (21)
        • CS(Computer Science) (2)
        • Background Knowledges (11)
        • Algorithm (2)
        • Mobile (3)
        • AWS (6)
        • Python (6)
        • MSW(MapleStoryWorlds) (8)
      • Coding Test (59)
        • 문제.zip (1)
        • BaekJoon_JavaScript (0)
        • Programmers_JavaScript (9)
        • BaekJoon_Python (23)
        • Programmers_Python (10)
        • Undefined_Python (3)
        • Programmers_SQL (13)
      • 활동내역.zip (43)
        • 개인 (21)
        • Techeer (12)
        • Bootcamp (7)
        • Hackathon (1)
        • TeamProjects (2)
      • 여기 괜찮네??(사이트 | App) (5)
      • 재미있는 주제들 (8)
      • 개발 외 공부 저장소 (11)
        • 생산운영관리 (3)
        • 생활속의금융 (6)
        • 경영정보시스템 (2)
  • 링크

    • TimeMap.dmg (Portfolio)
    • GitHub 바로가기
    • 오픈프로필(카카오톡)
    • Medium 바로가기
    • Disquiet 바로가기
    • LinkedIn 바로가기
  • 인기 글

  • 태그

    Python
    programmers
    JavaScript
    TypeScript
    HTML
    SQL
    프로그래머스
    react
    CSS
    Baek Joon
  • 최근 글

  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.1
ThreeLight
[TypeScript] TypeScript Grammar - 01
상단으로

티스토리툴바