Convert String to Number
Fill in the Blank Easy
Question
Fill in the blank to convert the string "42" to the number 42.
Code
let str = "42";
let num = ___(str);
console.log(num + 8); // 50
Hint
There is a built-in function named after the target type.
Explanation
Number() converts a string to a number. Number("42") returns 42 (the number), so num + 8 gives 50. Other options include parseInt() and the unary + operator, but Number() is the most explicit.
Related Resources
Related Lessons
- Data Types
Learn about the fundamental data types in programming.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.