TypeScript | TypeScript Functions | Question8

Last Updated :
Discuss
Comments

Which of the following is the correct way to cast a string to a number in TypeScript?

let num: number = <string> "42";

let num: number = "42" as number;

let num: number = Number("42");

let num: number = String("42");

Share your thoughts in the comments