Make description and example better

This commit is contained in:
Larry Lu
2018-12-04 12:43:44 +08:00
parent 932f9f87ed
commit 5ecda00b33

View File

@ -1,13 +1,13 @@
### isValidJSON ### isValidJSON
Checks if the provided argument is a valid JSON. Checks if the provided string is a valid JSON.
Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON. Use `JSON.parse()` and a `try... catch` block to check if the provided string is a valid JSON.
```js ```js
const isValidJSON = obj => { const isValidJSON = str => {
try { try {
JSON.parse(obj); JSON.parse(str);
return true; return true;
} catch (e) { } catch (e) {
return false; return false;