Knowledge

Literal (computer programming)

Source 📝

90:
are symbols that can take on one of a class of fixed values, the constant being constrained not to change. Literals are often used to initialize variables; for example, in the following, 1 is an integer literal and the three letter string in "cat" is a string literal:
382:
data interchange format is based on a subset of the JavaScript object literal syntax, with some additional restrictions (among them requiring all keys to be quoted, and disallowing functions and everything else except data literals). Because of this,
484: 460: 387:
every valid JSON document (except for some subtleties with escaping) is also valid JavaScript code, a fact exploited in the
416: 155:), objects can also be represented by literals. Methods of this object can be specified in the object literal using 516: 372: 87: 36: 159:. The brace notation below, which is also used for array literals, is typical for object literals: 148: 68: 64: 44: 28: 83: 137: 52: 40: 60: 8: 450: 72: 466: 456: 400: 156: 48: 132:, literals of a given type are generally a token type, with a grammar rule, like "a 405: 133: 129: 20: 446: 421: 368: 56: 426: 510: 410: 225:), an object with methods can be written using the object literal like this: 76: 35:. Almost all programming languages have notations for atomic values such as 222: 470: 32: 218: 214: 152: 388: 379: 16:
Notation for representing a fixed value in source code
136:" for an integer literal. Some literals are specific 508: 27:is a textual representation (notation) of a 445: 509: 208: 367:These object literals are similar to 13: 417:Hexadecimal floating-point literal 413:– a file literal or stream literal 14: 528: 217:(as well as its implementations 144:for the Boolean literal "true". 55:; some also have notations for 477: 439: 1: 432: 260:"very interesting" 59:and compound values such as 57:elements of enumerated types 7: 455:. McGraw-Hill. p. 45. 394: 10: 533: 151:-oriented languages (like 82:In contrast to literals, 371:in other languages like 227: 161: 93: 517:Programming constructs 41:floating-point numbers 75:is a literal for the 489:IBM Knowledge Center 31:as it is written in 452:Systems programming 209:Literals of objects 73:anonymous function 47:, and usually for 462:978-0-07-017603-4 401:Character literal 369:anonymous classes 157:function literals 524: 501: 500: 498: 496: 481: 475: 474: 443: 406:Function literal 363: 360: 357: 354: 351: 348: 345: 342: 339: 336: 333: 330: 327: 324: 321: 318: 315: 312: 309: 306: 303: 300: 297: 294: 291: 288: 285: 282: 279: 276: 273: 270: 267: 264: 261: 258: 255: 252: 249: 246: 243: 240: 237: 234: 231: 204: 201: 198: 195: 192: 189: 186: 183: 180: 177: 174: 171: 168: 165: 143: 134:string of digits 130:lexical analysis 124: 121: 118: 115: 112: 109: 106: 103: 100: 97: 21:computer science 532: 531: 527: 526: 525: 523: 522: 521: 507: 506: 505: 504: 494: 492: 483: 482: 478: 463: 444: 440: 435: 422:Integer literal 397: 365: 364: 361: 358: 355: 352: 349: 346: 343: 340: 337: 334: 331: 328: 325: 322: 319: 316: 313: 310: 307: 304: 301: 298: 295: 292: 289: 286: 283: 280: 277: 274: 271: 268: 265: 262: 259: 256: 253: 250: 247: 244: 241: 238: 235: 232: 229: 211: 206: 205: 202: 199: 196: 193: 190: 188:"cat" 187: 184: 181: 178: 175: 173:"dog" 172: 169: 167:"cat" 166: 163: 141: 126: 125: 122: 120:"cat" 119: 116: 113: 110: 107: 104: 101: 98: 95: 17: 12: 11: 5: 530: 520: 519: 503: 502: 491:. 18 June 2009 476: 461: 437: 436: 434: 431: 430: 429: 427:String literal 424: 419: 414: 408: 403: 396: 393: 228: 210: 207: 162: 94: 15: 9: 6: 4: 3: 2: 529: 518: 515: 514: 512: 490: 486: 480: 472: 468: 464: 458: 454: 453: 448: 447:Donovan, John 442: 438: 428: 425: 423: 420: 418: 415: 412: 411:Here document 409: 407: 404: 402: 399: 398: 392: 390: 386: 381: 376: 374: 370: 226: 224: 220: 216: 160: 158: 154: 150: 145: 139: 135: 131: 92: 89: 85: 80: 78: 77:function type 74: 70: 66: 62: 58: 54: 50: 46: 42: 38: 34: 30: 26: 22: 493:. Retrieved 488: 479: 451: 441: 384: 377: 366: 223:ActionScript 212: 146: 127: 81: 24: 18: 391:technique. 33:source code 485:"Literals" 433:References 219:JavaScript 215:ECMAScript 153:ECMAScript 53:characters 88:constants 84:variables 511:Category 449:(1972). 395:See also 308:function 272:function 147:In some 138:keywords 49:Booleans 37:integers 359:method2 347:method1 302:method2 266:method1 140:, like 69:objects 65:records 45:strings 25:literal 495:13 May 471:298763 469:  459:  385:almost 353:newobj 341:newobj 233:newobj 194:length 149:object 111:string 67:, and 61:arrays 43:, and 389:JSONP 317:alert 281:alert 71:. An 29:value 497:2020 467:OCLC 457:ISBN 380:JSON 378:The 373:Java 329:var2 323:this 293:var1 287:this 254:var2 248:true 242:var1 182:name 142:true 51:and 23:, a 362:(); 350:(); 230:var 221:or 213:In 128:In 96:int 86:or 19:In 513:: 487:. 465:. 375:. 338:}; 311:() 299:}, 275:() 200:57 79:. 63:, 39:, 499:. 473:. 356:. 344:. 335:} 332:) 326:. 320:( 314:{ 305:: 296:) 290:. 284:( 278:{ 269:: 263:, 257:: 251:, 245:: 239:{ 236:= 203:} 197:: 191:, 185:: 179:{ 176:} 170:, 164:{ 123:; 117:= 114:s 108:; 105:1 102:= 99:a

Index

computer science
value
source code
integers
floating-point numbers
strings
Booleans
characters
elements of enumerated types
arrays
records
objects
anonymous function
function type
variables
constants
lexical analysis
string of digits
keywords
object
ECMAScript
function literals
ECMAScript
JavaScript
ActionScript
anonymous classes
Java
JSON
JSONP
Character literal

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.