Use “+” to convert string to number

amrataabdallh

Amr Ataa

Posted on January 11, 2023

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
💖 💪 🙅 🚩
amrataabdallh
Amr Ataa

Posted on January 11, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related