Interview practice question
Converting strings to numbers safely
Frontend Engineering · JavaScript Core · Beginner
You need to convert user input strings to numbers. What approach do you use, and what pitfalls exist?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Number(), parseInt/parseFloat, unary +.
- parseInt needs radix; stops at invalid chars.
- Number("") is 0.
- Check Number.isNaN / isFinite.
- Validate input.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.