/typescript/

TypeScript part 14 (union type)

2017-03-04 13:55:30

TypeScript

let age = 17;
age = 18;
// age = '19'; <- error

let age2:number = 17;
age2 = 18;
// age2 = '19'; <- error

let age3:number | string = 17;
age3 = 18;
age3 = '19';

JavaScript

var age = 17;
age = 18;
// age = '19'; <- error
var age2 = 17;
age2 = 18;
// age2 = '19'; <- error
var age3 = 17;
age3 = 18;
age3 = '19';