Skip to main content
D
JavaScript
JavaScript Type Conversion

JavaScript Type Conversion

JavaScript type conversion changes data from one format to another.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript often needs to convert data types to perform calculations. If a user types the number "5" into a text box, JavaScript sees it as a string. Developers must convert it to a real number before doing math.

Example

Example
1/* this converts data types */
2let str = "3.14";
3let num = Number(str);
4let backToStr = String(num);

Key Points

  • The `Number()` function converts strings to numbers.
  • The `String()` function converts numbers to strings.
  • JavaScript sometimes converts types automatically.
  • Automatic conversion can lead to unexpected bugs.

Up Next

Continue your journey with the next topic.

Go to JS Typeof