Posted on February 17 - 2020 in

Turn a string into a number using JavaScript

Like most things in JavaScript, a string can be turned into a number in lots of different ways.

However, there is one way which is particularly easy to implement. Simply place a ‘+’ before your variable to convert it to an integer.

const number = '123'
const convertedNumber = +number

If you don’t believe me you can test this by using ‘typeof’ on convertedNumber and see the result in all its glory!

https://codepen.io/tomblinx/pen/NWqNozy?editors=0011

If you have anything further to add, please leave a comment below and let me know!

Start your project

If you feel I can help you with web design project I'd love to hear from you. Getting started is as easy as dropping me an email to start the discussion.

Start Project