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?
The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array. Values created with anonymous functions are methods of your object. Simple values are properties.
Literals or constants are the values we write in a conventional form whose value is obvious. In contrast to variables, literals (123, 4.3, "hi") do not change in value. These are also called explicit constants or manifest constants.
In plain English, an object literal is a comma-separated list of name-value pairs inside of curly braces. Those values can be properties and functions. Here's a snippet of an object literal with one property and one function. var greeting = {
Literal values (constants) are exact values (alphabetic or numeric). These values are also the constants that you use in expressions, such as the numeric value 100, or the string "John Smith".
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With