Skip to content

Instantly share code, notes, and snippets.

@BlakeWilliams
Created March 16, 2016 17:23
Show Gist options
  • Select an option

  • Save BlakeWilliams/35c7bb1069629fb28e95 to your computer and use it in GitHub Desktop.

Select an option

Save BlakeWilliams/35c7bb1069629fb28e95 to your computer and use it in GitHub Desktop.
const json = '[]'; // pretend this is the result of some api request
let jsonValue = JSON.parse(json);
if (json === null) {
jsonValue = [];
}
const json = '[]'; // pretend this is the result of some api request
const jsonValue = JSON.parse(json) || [];
@andyatkinson

Copy link
Copy Markdown

Makes sense. Prefer to avoid the ability for mutation when possible. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment