Interview Question

Difference between JSON and JavaScript object?

JSON is serialized text; a JavaScript object is a live runtime value.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

JSON is text in a restricted data grammar; a JavaScript object is a runtime value. • JSON requires double-quoted property names and strings. • Objects can contain methods, symbols, undefined, prototypes, and other values JSON cannot represent. • Parsing JSON creates JavaScript values.

Example

Code
const json = '{"count":2}';
const object = JSON.parse(json);
console.log(object.count);
Output
2

Quick Revision

JSON is serialized text; a JavaScript object is a live runtime value.