TypeScript variable
Variable
TypeScript covers JavaScript grammer.
let
let flag: boolean = false;
let is variable identifier, it’s like swift, but not const.
We can also use var same as javascript
const
const x = 111;
TypeScript type
- boolean
- number
- string
- array
- class
- interface
- enum
- function
javascript also has type, but it’s ambiguous.
Some are from Java, C# etc…
Number
let decimal: number = 11; let hex: number = 0xf1ad; let binary: number = 0b1212; let octal: number = 0o544;
String
let firstname: string = "kotori"; firstname = 'umi';
Array
let list: number[] = [1,2,3]; let nlist: Array<number> = [1,2,3]; let slist: string[] = ['Honoka', 'Kotori', 'Umi'];
Tuple
let x: [string, number]; x = ["xxxx", 10]; //x = [10, "xxxx"]; Error!!!!
Any
Any type is O.K. Umm.. finally, var
let umm: any = 1; umm = "I am string";