Navigate back to the homepage

how to add number to string in typescript?

Infinitbility
TypeScript
July 27th, 2022 · 1 min read
how to add number to string in typescript?

Add a number to a string in typescript

To add the number to a string in typescript, you can use the + addition operator or ${} template literal to add a number in a string both can add the number to a string.

1// ✅ Using `+` addition operator
25 + "0" 👉️ "50"
3
4// ✅ Using `${}` template literal
5`${5}0` 👉️ "50"

Today, I’m going to show you How do I add a number to a string in typescript, as above mentioned here, I’m going to use the + addition operator or ${} template literal to add the number to a string.

Let’s start today’s tutorial how do you number to string in typescript?

Add a number to string in typescript using addition operator

Here, I created two variables and stored the dollar sign in the first variable and the number in the second variable, and concatenated them using the addition operator.

1const str: string = "$";
2const num: number = 904;
3
4// ✅ Using `+` addition operator
5const price: string = str + num;
6console.log(price); // 👉️ '$904'

Add a number to a string in typescript using template literal

Here, I created two variables and stored the dollar sign in the first variable and number in the second variable, and concatenated them using template literal.

1const str: string = "$";
2const num: number = 904;
3
4// ✅ Using `${}` template literal
5const price: string = `${str}${num}`;
6console.log(price); // 👉️ '$904'

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to call script type module function in javascript?

how to call script type module function in javascript?

An example of call script type module function in javascript with step by step guide.

July 26th, 2022 · 1 min read
how to upload base64 image to ipfs?

how to upload base64 image to ipfs?

An example of uploading base64 image to ipfs in javascript with the step-by-step guide.

July 26th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]