TGViewer
Web Development - HTML, CSS & JavaScript Web Development - HTML, CSS & JavaScript @javascript_courses · 55.7K subscribers
Post #3692 1.73K
You can convert it:

let numberAge = Number(age);
console.log(numberAge);


Now:
25 is a number.

8️⃣ Converting to String

Use "String()".

let age = 25;
let textAge = String(age);
console.log(typeof textAge);


Output:
string


9️⃣ Converting to Boolean

Use "Boolean()".

console.log(Boolean(1)); // Output: true

console.log(Boolean(0)); // Output: false


Some common falsy values are:

• false
• 0
• ""
• null
• undefined
• NaN

Most other values are truthy.

Understanding truthy and falsy values will become very useful when writing conditions.

🔟 Type Coercion

JavaScript can sometimes automatically convert values between types.

For example:
console.log("5" + 2);

Output:
``text
52``


Why?

Because
+

with a string causes the number to be converted into a string.

But:
console.log("5" - 2);

Output:
``text
3``


JavaScript converts
"5"

into a number for the subtraction.

This behavior is called type coercion.

🚀 Double Tap ❤️ For Part-3
  • ❤ 12
  • 🔥 2
More from @javascript_courses
  1. Oct 4, 2026DSA Handwritten Notes
  2. Sep 28, 2026To learn web design and development from basic to advanced levels, you can follow these st…
  3. Sep 27, 202610 Websites Every Developer & AI Enthusiast Should Bookmark ✅ roadmap.sh – Step-by-step le…
  4. Sep 26, 2026🔹 Escape Characters 2️⃣5️⃣ New Line You can use \n and \t: const message1 = "Hello\nWorld…
  5. Sep 26, 2026const fileName = "report.pdf"; console.log(fileName.endsWith(".pdf")); // true 🔹 Finding…
  6. Sep 26, 2026💻 JavaScript Roadmap 2026 — Part 8 🟢 Strings & String Methods Strings are used to repres…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →