JS Built-ins
JSONparsebeginner

JSON.parse() β€” invalid JSON throws

πŸ“– Usage Example
JSON.parse('{"x":{"y":2}}').x.y  // β†’ 2

JSON.parse() handles nested JSON objects recursively.

JSON.parse Throws on Invalid Input

JSON.parse('invalid') throws a SyntaxError when the input is not valid JSON.

Challenge: Verify the error is thrown.

πŸ’‘ Hints (1)
  • β€’ Wrap the call in an arrow function for toThrow().