bernie2436 bernie2436 - 1 year ago 51
Javascript Question

What is the meaning of "literal" in the phrase object literal notation?

In Javascript: The Good Parts Douglas Crockford writes that one of Javascript's good ideas is "expressive object literal notation." I understand that he is basically complimenting JSON.

But what is "literal" about this notation? Are there are other languages that use "expressive object literal notation?" Are there languages that don't? What exactly does he mean?

Answer Source

About "complimenting JSON": He specified it.

The "literal" part: Googling "object literal" provides two top resources: MDN and Wikipedia. To quote the latter:

In computer science, a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values such as integers, floating-point numbers, and strings, and usually for booleans and characters; some also have notations for elements of enumerated types and compound values such as arrays, records, and objects.

Basically, all syntax constructs whose use lead to a defined type can be called a literal. (E.g., a string literal, "abc".) It's a technical term that denotes, that "literally" writing something in this or that way leads to a certainly typed variable exclusively (in contrast to constructs, that look like something else, like array() in PHP).