sarpay
2/3/2020 - 9:38 AM

Types, Casting & Inline Declaration

Casting

Number

var x = '1';
var numX = Number(x);
this.additionalPrice = Number(result.additionalPrice.toFixed(2));

String

let anyVar = 1234
let txtLength = String(anyVar).length; // returns 4

Inline Type Declaration

let anyVar = 'some text';
let endsWith = (<string>anyVar).endsWith('t'); // returns true
let endsWith = (anyVar as string).endsWith('t'); // returns true