JS Built-ins
StringStringbeginner

String() β€” convert null and undefined

πŸ“– Usage Example
String(42)         // β†’ '42'
String(true)       // β†’ 'true'
String(null)       // β†’ 'null'
String(undefined)  // β†’ 'undefined'

Use String() to safely convert any value to its string representation.

String Constructor β€” null & undefined

Unlike template literals via concatenation, String(null) β†’ 'null' and String(undefined) β†’ 'undefined'.

Challenge: Implement toStr(val) that uses String(val) and returns the result.

toStr(null)      // β†’ 'null'
toStr(undefined) // β†’ 'undefined'
πŸ’‘ Hints (1)
  • β€’ `String(null)` is safe β€” it will not throw like `null.toString()` would.