Categories
TypeScript Answers

How to cast a number to a string in TypeScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *