Type Coercion

Type coercion is when a programming language automatically converts a value from one type to another (e.g., number to string).

Types

  • Implicit: Done automatically by the language
  • Explicit: Done manually by the developer (e.g., Number("42"))

Common in Weak Typing

  • "5" + 1"51" (number coerced to string)
  • "5" - 14 (string coerced to number)

See: JavaScript Type Coercion Examples