Navigate back to the homepage

node js convert string to number

Infinitbility
Node
July 7th, 2022 · 1 min read
node js convert string to number

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To convert a string to a number in node js, you can use the + plus operator it’s the fastest way to convert a string to a number.

In the following example, we will take the sample string variable, and convert it into an integer using the plus operator.

1let text = "24325";
2
3// using plus operator
4let num = +text;
5console.log(num) // 24325

Today, I’m going to show you How do i convert string to number in node js, as above mentioned here, I’m going to use the plus operator and string interpolation.

Let’s start today’s tutorial how do you convert string to number in node js?

In this example, we will do

  1. take an example of a string variable
  2. use the plus operator
  3. print the converted number on the page screen
1var http = require("http");
2
3//create a server object:
4http
5 .createServer(function (req, res) {
6 let text = "24325";
7 let num = +text;
8 res.write(`${num} is ${typeof num}`); //write a response to the client
9 res.end(); //end the response
10 })
11 .listen(8080); //the server object listens on port 8080

In the above node js example, we have taken the example of converting a string to a number and return the convert number and their datatype in the response.

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 remove double quotes from string in react native?

how to remove double quotes from string in react native?

An example of remove double quotes from string in react native with step by step guide.

July 6th, 2022 · 1 min read
how to replace string in node js?

how to replace string in node js?

An example of replace string in node js with a step-by-step example.

July 6th, 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]