To number: Number("3.5"), parseInt(), parseFloat(), or unary plus +"3"
To string: String(42) or (42).toString()
To boolean: Boolean(value) or !!value
Automatic conversion
JavaScript also converts types automatically, sometimes surprisingly: "5" + 2 is "52" (string joining) but "5" - 2 is 3.
💡 Key Takeaways: JavaScript Type Conversion
Mastering JavaScript Type Conversion helps you write clean and reliable JavaScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.