I have confusion about what exactly people mean by Object Literals, JSON, JavaScript Objects, to me they seem similar:
{foo: \'bar\', bar : \'baz\'}
Object Literal:
Referencing mozilla ,
An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}).
Javascript Object:
Referencing mozilla,
In JavaScript, an object is a standalone entity, with properties and type
JSON:
Referencing mozilla and mozilla
JSON (JavaScript Object Notation) is a data-interchange format. It closely resembles a subset of JavaScript syntax, although it is not a strict subset.JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null. It is based upon JavaScript syntax but is distinct from it: some JavaScript is not JSON, and some JSON is not JavaScript.
In loose words,
An object
is a javascript variable which can have properties and type.
An object literal
is a way to assign properties and associated values to object
.
JSON is a more strict object literal
used for data interchange which is wrapped as string.
(Usually, strictness is there to allow all languages to use it, we cannot use function
as value, key
should always be in double quotes (In object literal its not compulsory))