What is the correct fix?
const raw = '{bad json}';
const cfg = JSON.parse(raw);
- Wrap the parse in a
try/catchblock - Wrap the parse in a
try/finallyblock - Call
JSON.stringify(raw)before parsing - Compare
rawagainst an empty string
JSON.parse throws on malformed input; catch it instead of crashing.
Play Problem Solving ▸