DEV Community

Amr Ataa
Amr Ataa

Posted on

Use “+” to convert string to number

You might be using Number() and parseInt() to convert string to number.

// ❌
let str = '123'
let num = Number(str) // 123
let num2 = parseInt(str) // 123
Enter fullscreen mode Exit fullscreen mode
// ✅
let str = '123'
let num = +str // 123
Enter fullscreen mode Exit fullscreen mode

Top comments (0)