let decimal: number = 6;
let hex: number = 0xf00d;
let binary: number = 0b1010;
let octal: number = 0o744;
Number
let color: string = "blue";
color = 'red';
String
let fullName: string = `Bob Bobbington`;
let age: number = 37;
let sentence: string = `Hello, my name is ${ fullName }.
I'll be ${ age + 1 } years old next month.`
let list: number[] = [1, 2, 3];
Array
let list: Array<number> = [1, 2, 3];
let list: number[] = [1, 2, 3];
Array
let list: Array<number> = [1, 2, 3];
// Declare a tuple type
let x: [string, number];
// Initialize it
x = ["hello", 10]; // OK
// Initialize it incorrectly
x = [10, "hello"]; // Error
Tuplas
// OK
console.log(x[0].substr(1));
// Error, 'number' does not have 'substr'
console.log(x[1].substr(1));
enum Color {Red, Green, Blue};
let c: Color = Color.Green;
Enum
// OK
console.log(x[0].substr(1));
// Error, 'number' does not have 'substr'
console.log(x[1].substr(1));