Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 226
bernie2436 Avatar asked Jan 08 '14 14:01

bernie2436


People also ask

What is object literal notation?

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.

What does literal mean in programming?

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.

What is object object literal?

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 = {

What is a literal value?

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".


1 Answers

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).

like image 162
Boldewyn Avatar answered Sep 23 '22 04:09

Boldewyn