Sometimes, we want to cast a number to a string in TypeScript.
In this article, we’ll look at how to cast a number to a string in TypeScript.
How to cast a number to a string in TypeScript?
To cast a number to a string in TypeScript,. we can use the toString
method.
For instance, we write
const pageNumber: number = 3;
const s: string = pageNumber.toString();
to call pageNumber.toString
to return the number converted into a number string and then assign the string to s
.
Conclusion
To cast a number to a string in TypeScript,. we can use the toString
method.