index [nostarch.com] · 2017. 11. 2. · animation avoiding stutter, 230 cat in ellipse, 230...

23
INDEX Symbols && operator, 17, 20, 96 * operator, 13, 18, 156 * = operator, 34 {} (block), 31, 44, 85 {} (object), 63, 113 - operator, 14, 15, 18 -= operator, 34 = operator, 25, 64, 168, 170, 197 == operator, 16, 19, 66, 79 === operator, 19, 79, 410 / operator, 14 /= operator, 34 > operator, 16 >= operator, 16 < operator, 16 <= operator, 16 - operator, 34 % operator, 14, 34, 286, 408, 417, 419 + operator, 13, 15, 18, 156, 403 ++ operator, 34 += operator, 34 ?: operator, 17, 20 [] (array), 60 [] (subscript), 61 || operator, 17, 19, 51, 96, 123, 326, 408 200 (HTTP status code), 300, 354 204 (HTTP status code), 360 2d (canvas context), 277 400 (HTTP status code), 424 404 (HTTP status code), 300, 359, 374, 376 405 (HTTP status code), 358 406 (HTTP status code), 420 500 (HTTP status code), 359, 363 A a (HTML tag), 210, 224, 226, 318 Abelson, Hal, 190 absolute path, 424 absolute positioning, 229, 233, 241, 245, 250 abstract syntax tree, see syntax tree abstraction, 82, 84, 85, 91, 191, 208, 218 acceleration, 268 Accept header, 312, 363, 420 access control, 127, 151, 178, 371 Access-Control-Allow-Origin header, 305 actionTypes object, 130 activeElement property, 317 actor, 256, 261, 266–267, 291 actorAt method, 266 addEntry function, 66 addEventListener method, 236, 270, 356 addition, 13, 117 address, 299 address bar, 209, 299, 301 adoption, 153 age difference (exercise), 95, 411 alert function, 27, 47, 211 algorithm, 423 algorithmic optimization, 398, 405 alignment, 114 all function, 313, 421 alpha, 343 alphanumeric character, 155 alt attribute, 221 ALT key, 240 altKey property, 240 ambiguity, 202 AMD, 183, 185 American English, 156 ampersand character, 211, 301 analysis, 139, 143 ancestor element, 262 ancestry example, 87–90, 92–95 ANCESTRY_FILE data set, 88 angle, 231, 282–283, 341, 419 angle brackets, 210 animate method, 266 Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

Upload: others

Post on 22-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

  • INDEX

    Symbols&& operator, 17, 20, 96* operator, 13, 18, 156*= operator, 34{} (block), 31, 44, 85{} (object), 63, 113- operator, 14, 15, 18-= operator, 34= operator, 25, 64, 168, 170, 197== operator, 16, 19, 66, 79=== operator, 19, 79, 410/ operator, 14/= operator, 34> operator, 16>= operator, 16< operator, 16

  • animationavoiding stutter, 230cat in ellipse, 230collision detection, 265frames for, 285–286, 290–291game, 264, 266–269, 271getting elements by tag name, 233mouse trail, 250off-screen, 244scheduling, 230simple, 129, 134sprite, 293stopping, 271SVG vs. canvas, 295

    anonymous function, 178appendChild method, 220, 260, 416Apple, 213application (of functions), see function

    applicationapply method, 86, 101approximation, 119arc, 281–283arc method, 282, 420arcTo method, 281, 282area, 341argument, 27, 47, 51, 163, 192arguments object, 74, 86, 409argv property, 350arithmetic, 13, 18, 198Armstrong, Joe, 98array

    creation, 60, 91, 121, 409defined, 64Egg support, 202every method, 96filtering, 88flattening, 95forEach method, 84as grid, 120, 343higher-order functions and, 87indexing, 61, 409, 417length property, 62, 121map method, 89methods, 72objects and, 78random element from, 123reverse method, 78searching, 69, 72slice method, 73

    some method, 96splice method, 377as table, 68traversal, 83

    Array constructor, 121Array prototype, 102, 104array-like object, 86, 186, 318, 323, 353arrow function, 125artificial intelligence, 119, 130, 135,

    201, 412artificial life, 119, 254, 328artificial stupidity (exercise), 135, 412ASCII art, 352assert function, 149assertion, 149, 150assignment, 25, 34, 168, 170, 202, 416assumption, 148, 150asterisk, 13, 156asynchronous I/O, 183, 304, 348asynchronous programming

    callbacks, 304, 308code execution path and, 185defined, 272dependencies and, 183error handling, 307functions and, 352Node and, 348overview, 348, 349parallelism and, 349promise interface, 310reading files, 323writable streams, 356

    attack, 305attribute, 210, 222, 332, 421, 422Aurelius, Marcus, 234authorization, 371autocompletion (exercise), 328, 421autofocus attribute, 317automatic semicolon insertion, 24avatar, 254average function, 90, 95, 96, 411axis, 268, 277, 287–288

    BBabbage, Charles, 58background, 254, 260–261, 265, 291background (CSS), 250, 254, 261backgroundReadFile function, 184, 306

    430 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • backslash characterboundary markers, 166escaping in regular expressions,

    154, 166escaping in strings, 14paths using, 364

    backtracking, 162, 165backward compatibility, 177ball, 297, 420Banks, Iain, 252bean counting (exercise), 56, 409beforeunload event, 246behavior, 122, 129, 172, 201, 412–413benchmark, 225, 389, 395Berners-Lee, Tim, 298best practices, 3bezierCurve method, 281binary data, 3, 353binary number, 11, 12, 68, 142,

    162, 322binary operator, 13, 15, 23bind method, 94, 101, 125bit, 4, 12, 16, 68bitmap graphics, 284, 297Blob type, 324block, 31, 32, 42, 145, 146, 192block comment, 36, 165block element, 224, 226–227blocking, 183, 230, 246, 248, 304,

    348, 354blur event, 245–246blur method, 317body (HTML tag), 210–211, 216body (HTTP), 301–303, 355, 360,

    361, 374body property, 216, 217, 219bold, 226book analogy, 175, 188Book of Programming, The, 10, 346Boolean

    conditional execution, 29conversion to, 19, 29, 32defined, 16Egg support, 197immutable types, 65using with while loop, 31

    Boolean function, 29border (CSS), 225, 226border-radius (CSS), 241

    bouncing, 122, 255, 257–258, 265,267, 297

    BouncingCritter type, 122boundary, 160, 161, 166, 170, 172,

    291, 414box, 151, 215, 254, 297, 420box shadow (CSS), 262br (HTML tag), 422braces, see curly bracesbranching, 160, 162branching recursion, 51, 289break keyword, 33, 35breakpoint, 143British English, 156browser

    bitmaps in, 297color field support, 336compatibility between, 213console output, 27dialog boxes in, 28doctype and, 211events in, 236global scope, 77graceful degradation, 387history of JavaScript, 6JavaScript support, 2long polling, 369old, 213private namespace pattern, 180responsiveness, 390security, 212–213, 305, 364sessionStorage, 327XMLHttpRequest and, 302–304

    browser wars, 213Browserify, 183brush, 332, 336–337, 340bubbling, see event propagationbucket fill, 343, 423budget, 387Buffer type, 353, 356bug

    browser history, 213decoupling and, 177defined, 81, 139lastIndex property and, 167regular expressions and, 166

    business software, 302button, 235, 301, 318, 328, 339

    INDEX 431Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • button (HTML tag), 212, 236, 241, 251,319, 325, 327

    byName object, 92, 95

    CC (programming language), 389cache, 182, 184, 415call method, 101, 105, 114, 126,

    131, 199call protocol, 396call stack, 46–48, 51, 145, 147, 149, 396callback function

    defined, 306error arguments, 307event handlers, 235promises and, 308readable streams, 355writable streams, 356

    calling (of functions), see functionapplication

    camel case, 36, 227cancelAnimationFrame function, 248canvas

    arcTo method, 282bezierCurve method, 281circles, 281clearRect method, 285color picker exercise, 342context, 277, 339cross-domain requests, 338defined, 275drawGraph function, 393drawing text in, 284filling and stroking, 278graphics options in browser, 295loading pixel data into, 285path, 278performance and, 295size, 277, 278strokeTo method, 279toDataURL method, 337transformations in, 286–288

    canvas (HTML tag), 277, 332canvas property, 333CanvasDisplay type, 290, 291, 293capitalization

    with censored keyboard, 417in header names, 304

    in property names, 227in variable names, 35–36

    capture group, 158, 159, 163–164, 373career, 253caret character, 155, 160, 170carnivore, 136carriage return, 169cascading, 228Cascading Style Sheets, see CSScase conversion, 62case keyword, 35case-sensitivity, 157, 304, 414casual computing, 2cat’s hat (exercise), 233catch keyword, 145, 147–148, 150, 413catch method, 310CD, 11celery, 367cell, 328censored keyboard (exercise), 250, 417center, 263centering, 230century, 96, 411certificate, 311chaining, 309, 362change event, 317, 320, 327, 339, 425chapter, 175character, 14, 240, 320character category, 171character encoding, 353charAt method, 56, 74charCode property, 240, 417charCodeAt method, 240, 403chat, 208checkbox, 316, 321, 328, 422checked attribute, 316, 321chess board (exercise), 38, 408child node, 217, 218, 220, 243childNodes property, 218, 221, 418choice, 160Chrome, 213circle, 231, 281–282, 341circle (SVG tag), 276circular dependency, 188, 415circus, 72class attribute, 220, 224, 228, 260, 262,

    333, 382className property, 224cleaning up, 146, 264

    432 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • clearing, 223, 275, 285, 288–289,291–292, 420

    clearInterval function, 248clearRect method, 285, 420clearTimeout function, 248cleverness, 186click event, 236, 238, 241, 421, 425client, 208, 310, 355, 368, 379clientHeight property, 225clientWidth property, 225clientX property, 242, 334clientY property, 242, 334clipboard, 212, 250clipping, 291cloneNode method, 383cloning, 383closePath method, 279closing tag, 210, 212closure, 48, 85, 202, 324, 397, 416–418code, 7, 23, 43, 165, 254code golf, 172code structure, 32, 41, 115, 175coin, 254, 255, 266–270, 294Coin type, 258, 267collaboration, 207collection, 5, 60, 62, 64, 78, 117, 412collision detection, 264–269, 420colon character, 17, 35, 63, 226color, 276, 278, 292, 332, 336, 342color (CSS), 226, 227color picker, 336color picker (exercise), 342, 423colWidths function, 108comma character, 192command key, 240command line, 347, 349–351comment, 36, 165, 202, 217, 368, 370,

    384, 416comment field reset (exercise),

    386, 425COMMENT_NODE code, 217CommonJS, 180–182, 188, 350, 351communication, 208, 310community, 348comparison

    of colors, 423creating Boolean values, 16of DOM nodes, 425of NaN, 17

    of numbers, 16, 28of objects, 66of strings, 16for switch statement, 35of undefined values, 19

    compass direction, 122, 129compatibility, 6, 207, 213, 303, 336compilation, 200, 389–390, 402, 416completion, 303, 328complexity, 3, 81, 91, 99, 186, 399composability, 5, 90, 91, 186compositing, 336composition, 115computed property, 61computer, 1, 3concat method, 73, 95, 112, 417, 426concatenation, 15, 73, 112, 417,

    423, 424concurrency, 246conditional execution, 17, 29, 35, 38,

    196, 387conditional operator, 17, 20configuration, 169confirm function, 28Confucius, 2connection, 208, 299, 304, 306,

    311, 369consistency, 36, 207, 218console.log, 15, 27, 46, 75, 143constant, 76, 269constructor

    Error, 146inheritance using, 114instanceof operator and, 115overview, 103prototype property for, 103using without new keyword, 141

    content negotiation (exercise), 312,363, 420, 424

    Content-Length header, 300Content-Type header, 300, 354, 358, 364context, 277, 333–334, 339context menu, 239context parameter, 125, 126continue keyword, 34control flow, 29, 31–33, 46, 85,

    145, 310control key, 240control point, 280, 281

    INDEX 433Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • controls object, 333, 336convention, 36, 186Conway’s Game of Life, 328coordinates, 120, 241, 260, 277, 278,

    334, 422–423copying, 383copy-paste programming, 53, 176correlation, 67–69, 71cosine, 76, 231counter variable, 31, 33, 231, 408, 409,

    417, 421crash, 147, 150, 361, 375, 386createElement method, 221, 332, 416createPaint function, 333createReadStream function, 356, 359createServer function, 354, 356,

    372, 373createTextNode method, 221, 421createWriteStream function, 356, 360crisp, 295critters, 119

    action handlers and, 131–133animating, 126–128behavior, 129–130predators of, 136

    Crockford, Douglas, 206cross-domain request, 305, 338, 343cryptography, 311CSS, 227, 244, 261–262, 264, 275, 333ctrlKey property, 240curl program, 361curly braces, 31

    brace notation, 63for function body, 42for multiple loops, 408with parentheses, 84with pattern, 156–157

    cursor, 319–320curve, 280–281cycle, 217

    DDark Blue (game), 254dash character, 14, 155, 227data, 2, 59data attribute, 222, 223, 251data event, 356data format, 87, 218, 305data loss, 386

    data set, 68, 87, 111data structure, 59–79

    in ancestor example, 92–93when building programming

    language, 192lists, 78–79trees, 216–217using simple, 186in weresquirrel example, 60–61

    data URL, 337database, 303dataTable function, 112, 114date, 155, 156, 158Date constructor, 158–159date field, 336Date type, 177, 187Date.now function, 159, 371, 404dblclick event, 241debouncing, 248debugger statement, 143debugging

    defined, 140Error constructor, 145JavaScript weaknesses, 6overview, 139use strict and, 141using assertions, 150using catch keyword, 148using console.log, 143

    decentralization, 207decimal number, 11, 142, 162declaration, 226decodeURIComponent function, 301, 358,

    373, 424decoupling, 177deep comparison, 66, 79deep comparison (exercise), 79, 410default behavior, 226, 239, 417default keyword, 35default value, 20, 93, 278, 326, 409defensive programming, 127, 128define function, 183–185defineProperty function, 106, 113, 411degree, 282, 287DELETE method, 300–301, 357, 359,

    374, 384delete operator, 64denodeify function, 361deoptimization, 397, 402

    434 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • dependence, 67dependency, 176–177, 180, 183–184,

    188, 352deserialization, 87developer tools, 7, 27, 144, 147dialog box, 27, 28diamond, 296, 419digit, 11, 12, 142, 155–157, 173Dijkstra, Edsger, 118dimensions, 117, 119, 225, 253, 255,

    265, 277, 408dinosaur, 201direct child node, 228directions object, 122, 129directory, 353–354, 357–359, 364, 425disabled attribute, 318discretization, 119, 254, 265, 267, 271dispatching, 35, 372display, 260, 290, 295display (CSS), 226, 251, 380distance, 394division, 14division by zero, 14DNA, 92, 93do loop, 32doctype, 210–211document, 209, 215, 246, 275document format, 311, 312Document Object Model, see DOMdocumentation, 186, 347documentElement property, 216, 217, 304dollar sign, 25, 160, 163, 170DOM

    addEventListener, 236canvas element, 275cloneNode, 383construction, 218, 220, 222, 332, 380creating structures in JavaScript, 380CSS and, 275documentElement, 217events and, 241forms in, 315graphics in, 255object properties, 222overview, 216, 220selectors and, 229value property, 319

    domain, 209, 301, 305, 325, 338

    domain-specific language, 82, 142, 153,201, 229, 310, 380

    DOMDisplay type, 260, 290dot character, see period characterdouble-click, 241double-quote character, 14, 173,

    192, 211download, 7, 177, 232, 361, 368, 386draggable bar example, 242dragging, 242drawGraph function, 393drawImage method, 285, 287, 290,

    292–293, 420drawing

    building a program for, 331–344and canvas element, 275–297checkboxes, 422subsystems, in platform game,

    259–264drawing program example, 241, 331drawTable function, 109drawTalk function, 382, 383, 387drop-down menu, 316, 322duplication, 176, 415dynamic scope, 146dynamic typing, 139, 402

    EECMAScript, 6, 45, 125, 308, 427ecosystem, 119, 135, 136ecstatic module, 373editor, 255efficiency, 50, 182, 200, 255, 412Egg language, 191–203

    array support, 202comments in, 202environment, 198evaluator, 195functions in, 199overview, 191, 201parsing, 195uniformity, 192

    elegance, 50, 91, 193element, 210, 217, 222elementFromChar function, 124ELEMENT_NODE code, 217, 417elements property, 318ellipse, 230, 231

    INDEX 435Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • else keyword, 30elt function, 222, 332, 380email, 311email field, 336empty set, 165encapsulation

    defined, 99, 100importance of, 176inheritance and, 115using modules, 177–178, 186, 188

    encodeURIComponent function, 301, 370encoding, 208encryption, 311end event, 356end method, 355, 356, 358, 424enemies example, 168energy, 130–133, 412engine, 389engineering, 213ENOENT (status code), 359, 363ENTER key, 319, 339entity, 211entropy, 130enumerability, 106environment, 26, 196, 198, 247, 416equality, 16erase tool, 335, 336error, 139–142, 144, 147, 148error event, 307, 324, 360error handling

    asynchronous programmingand, 307

    catch keyword, 145catch method, 310ENOENT, 359for file server, 361HTTP status codes, 359long polling and, 386overview, 144, 145then method, 310unhandled exceptions, 147user experience and, 381using promises, 361

    error message, 195, 309, 327error recovery, 144error response, 300, 306, 359–361error tolerance, 127, 211Error type, 145, 147, 148, 359ESC key, 273

    escapingin HTML, 210, 212in regular expressions, 154–155, 166in strings, 14, 192in URLs, 301, 358, 370, 373

    Escher, M.C., 274eval, 180evaluate function, 195–196, 198evaluation, 180, 195, 200even number, 31, 56event handling

    asynchronous programming and,272, 304

    callbacks, 235default behavior, 239DOM and, 236event objects, 237event propogation, 237focus events, 245in games, 254, 273keyboard events, 239, 320load event, 284, 304reading from streams, 356scroll events, 244starting scripts, 246submitting forms, 319target property, 321

    event object, 237, 240–242, 334, 342event propagation, 237–238, 243,

    245, 246event type, 237every and some (exercise), 96, 411every method, 96evolution, 153, 176exception, 307, 361exception handling

    asynchronous programmingand, 307

    chaining actions and, 308vs. crashing, 361error handling and, 145overview, 148purpose of, 361toDataURL method and, 338try keyword, 145uncaught exceptions, 147

    exec method, 157–158, 167–168execution order, 29, 45, 46exercises, 2, 7, 37, 142

    436 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • exit method, 350expectation, 239experiment, 3, 7, 172, 240exploit, 213exponent, 13, 173, 414exponentiation, 32, 33exporting, 179, 182, 415exports object, 179, 181–182, 351, 415expression, 23–25, 28, 31, 33, 196expressivity, 2, 201extinction, 135extraction, 158

    Ffactorial function, 8failure, 306fallthrough, 35false, 16farm example, 52, 54, 160farmer, 87field, 315, 318, 321, 328, 425figlet module, 352file extension, 358file field, 316, 323file format, 168file reading, 323file server module, 379file server example, 357–362, 364,

    424, 425File type, 323FileReader type, 324, 339files property, 323filesystem, 323, 332, 339, 353–354,

    357, 425fill method, 279fillColor property, 284filling, 278–279, 284, 296fillRect method, 278, 285, 342,

    344, 422fillStyle property, 278, 332, 333, 337fillText method, 284, 419filter method, 88, 94, 109, 257, 411finally keyword, 146, 151, 413finish event, 361Firefox, 213, 303firewall, 365, 369firstChild property, 218fixed positioning, 245FizzBuzz (exercise), 38, 408

    flattening (exercise), 95flexibility, 6flipHorizontally function, 293, 419flipHorizontally method, 287flipping, see mirroringfloating-point number, 13flood fill (exercise), 343, 423flow diagram, 161, 162focus, 241, 245, 317–318, 320, 321,

    386, 425focus event, 245–246, 338focus method, 317fold function, 89font, 284, 340font-family (CSS), 227font-weight (CSS), 228food, for critters, 130, 132,

    134–135, 413food chain, 133, 136for attribute, 321for loop, 33, 124, 148, 397, 409, 410force-directed graph layout, 391,

    393–394for/in loop, 70–71, 105–107, 410, 411forEach method, 84, 125, 324, 418, 426form, 301–302, 315, 318–319, 365form (HTML tag), 315–316, 318, 339,

    379, 385, 425, 426form property, 318forwarding, 371fractal example, 289fractional number, 13, 173, 254fragmentation, 400frame, 285–286, 290–291, 293, 420framework, 54, 133fromCharCode function, 240, 403fs module, 353–354, 364fsp object, 362function

    body, 42declaration, 45–46definition, 27, 42, 45, 52higher-order, 84–86, 87, 89, 90, 125model of, 49as namespace, 177–179naming, 52–54overview, 41program division and, 175as property, 62

    INDEX 437Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • function, continuedpurity, 54scope, 43, 44, 125, 202as value, 45, 48, 83–84, 306, 418wrapping, 86

    Function constructor, 181, 184, 198,200, 327, 421

    function keyword, 42, 45, 179Function prototype, 102, 104future of JavaScript, 6, 26, 171,

    185, 308

    Ggame

    acceleration of character in, 240drawing display for, 290–294platform, 253–273running, 270

    game of life (exercise), 328, 422GAME_LEVELS data set, 273garbage collection, 12, 396, 399, 400garble example, 351gardening, 367gatherCorrelations function, 70gaudy home pages, 250generation, 328, 422generational garbage collection, 400get function, 308GET method, 300, 301, 303, 319,

    357, 425getAttribute method, 222, 224getBoundingClientRect method, 225,

    242, 334getContext method, 277getDate method, 159getDay method, 177getElementById method, 220getElementsByClassName method, 220getElementsByName method, 321getElementsByTagName method, 219, 221,

    223, 232, 417getFullYear method, 159getHours method, 159getImageData method, 342, 343getItem method, 325–326getMinutes method, 159getMonth method, 159getPrototypeOf function, 102, 104,

    202, 416

    getResponseHeader method, 303getSeconds method, 159getter, 113, 117getTime method, 159getURL function, 307getYear method, 159global object, 77, 125, 140, 350global scope, 43, 176, 178–179, 182,

    236, 350, 416globalCompositeOperation property, 336Goethe, Johann Wolfgang von, 314Google, 213graceful degradation, 388grammar, 23, 169grandfather, 92–93graph, 295, 390, 404graph layout, 391graphical user interface, 1graphics

    and canvas, 275canvas element, 277

    interface, 295in platform game, 262

    and DOM, 254–255encapsulation, 259

    vector vs. bitmap, 284GraphNode type, 392gravity, 268, 269greater than, 16greed, 165grid, 119–121, 422Grid type, 121groupBy function, 96grouping, 31, 96, 157–158, 163–164,

    411, 414

    Hh1 (HTML tag), 210, 224hard drive, 12, 323, 325, 348, 386hard-coding, 219, 296, 334hasEvent function, 68hash character, 202hasOwnProperty method, 106–107,

    202, 416head (HTML tag), 210–211, 216head property, 216header, 300–301, 303, 304, 306, 354height (CSS), 342help text example, 245

    438 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • helper function, 218herbivore, 133–136, 413hexadecimal number, 162, 301hidden element, 227, 251, 380higher-order function, 84–86, 87, 89,

    90, 125highlightCode function, 223history, 6, 99, 378Hoare, C.A.R., 80Hooke’s law, 393hooligan, 371Host header, 301, 304hot code, 390hover effect, 243, 244href attribute, 210, 219, 222, 337HTML, 209, 215, 217, 276, 332html (HTML tag), 211, 216HTML5 form fields, 336HTTP, 209, 299–301, 305,

    310–311, 360http module, 354–355, 363HTTPS, 209, 311, 355https module, 355human language, 2, 23, 41Hypertext Markup Language,

    see HTMLHypertext Transfer Prototol, see HTTP

    Iid attribute, 220, 228, 321, 379idempotency, 360, 424identifier, 192identitiy, 65if keyword, 29–30, 35, 170, 408image, 210, 221, 246, 275, 301,

    332, 338imagination, 253img (HTML tag), 210, 221, 226, 246,

    275, 285, 339implementation, 171implementation detail, 177implements (reserved word), 26in operator, 64, 69, 105–107, 410indentation, 32, 33index, 61, 109index property, 157index.html, 379indexOf method, 69, 72, 74, 154, 167,

    377, 421

    infinite loop, 34, 47, 130, 148, 409infinity, 14inheritance, 102, 114–116, 130,

    148, 359ini file, 168, 176initialization, 246, 379, 380inline caching, 402, 403inline element, 224, 226inlining, 396, 397inner function, 44, 85, 110, 417inner loop, 91, 163, 397, 401, 402innerHeight property, 245innerWidth property, 245input, 28, 144, 235, 255input (HTML tag), 245, 250, 316, 319,

    321, 323input event, 320, 421insertBefore method, 220install, 352installation, 177instance, 103instanceof operator, 115, 148instantiateTemplate function, 387, 426instantiation, 382instruction, 4integer, 13integration, 153, 218interconnection, 176interface

    canvas, 275design, 54, 177, 185, 217–218DOM as, 218modules and, 180objects as, 179overview, 99, 107sequence, 117table, 108

    interface (reserved word), 26interface design, 54, 177, 185, 217–218internationalization, 170Internet, 168, 208, 209, 212, 364, 365Internet Explorer, 213, 302interpretation, 7, 180, 195–196,

    200, 389interview question, 38inversion, 155invoking (of functions), see function

    applicationIP address, 209, 299, 301, 365

    INDEX 439Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • isEven (exercise), 56, 408isInside function, 243isNaN function, 30isolation, 99, 176–178, 180, 212iteration, 117

    JJacques, the weresquirrel, 60Java, 6JavaScript

    absence of, 387availability of, 2flexibility of, 6history of, 6, 207in HTML, 211syntax, 23uses of, 6versions of, 6weaknesses of, 6

    JavaScript console, 7, 15, 27, 143, 147,327, 349

    JavaScript Object Notation, see JSONjoin method, 62, 105, 110, 199, 351journal, 60, 63, 65, 66, 70, 75JOURNAL data set, 68JSON, 87, 305, 309, 325, 352, 425JSON.parse function, 87, 425JSON.stringify function, 87jump, 4jump-and-run game, 253jumping, 254, 268, 269just-in-time compilation, 390

    KKernighan, Brian, 138key code, 240, 270keyboard, 26, 239, 254, 270, 317–318keyboard focus, see focuskeyCode property, 240, 417keydown event, 239–240, 248, 270, 417keypress event, 240, 417keyup event, 239, 240, 270keyword, 24, 26, 223Khasekhemwy, 320Knuth, Donald, 40Kurds, and censored keyboard, 250

    Llabel, 284, 297label (HTML tag), 321labeling, 321landscape example, 44lastChild property, 218lastIndex property, 167–168lastIndexOf method, 72Last-Modified header, 300Lava type, 258, 267layering, 186, 208layout, 224–226laziness, 225leaf node, 217leak, 213, 273, 338, 364, 424left (CSS), 229–231, 233, 342legend, 123length property

    for arrays, 62, 83for strings, 53, 61, 74, 409

    less than, 16let keyword, 26, 45level, 418Level type, 256lexical scoping, 44, 85library, 177, 218, 306, 350–352life expectancy (exercise), 96, 411LifeLikeWorld type, 130line, 278–282, 335, 419line break, 14, 169line comment, 36, 165line tool, 332, 334–335line width, 278, 286lineCap property, 335lines of code, 199lineTo method, 279, 282lineWidth property, 278, 333, 335, 337link, 210, 218–219, 239, 241, 332link (HTML tag), 264linked list, 78, 410, 427list (exercise), 78, 410listen method, 354–355listening (TCP), 208, 354literal expression, 23, 153, 194, 196literate programming, 176live data structure, 215, 221, 229, 418live view, 368, 382lives (exercise), 273, 418

    440 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • load event, 246, 284, 293, 304, 324,339, 420

    loading, 183local scope, 176, 200local variable, 43, 48, 84, 85, 202,

    409, 418localhost, 354localStorage object, 325–326, 384locked box (exercise), 151, 413logging, 143logical operators, 17long polling, 368–370, 376–377, 386loop

    body, 32, 34defined, 31for, 33, 83nested, 84, 92over matches, 168termination of, 33while, 5

    lycanthropy, 60, 66

    Mmachine code, 3, 200, 389malicious script, 212, 246man-in-the-middle, 311map, 70, 105, 107, 257, 318, 405,

    411, 427map method, 89, 108–110, 125, 351, 411Marcus Aurelius, 234match method, 158, 168matching, 154, 160–162, 167, 172Math object, 56, 61, 75–76Math.abs function, 422Math.acos function, 76Math.asin function, 76Math.atan function, 76Math.ceil function, 77, 265, 292Math.cos function, 76, 231, 341, 420mathematics, 50, 85Math.floor function, 76, 265, 292Math.max function, 28, 61, 75, 291Math.min function, 28, 56, 75, 291, 422Math.PI constant, 76, 282Math.random function, 76, 123, 133,

    259, 328Math.round function, 77Math.sin function, 76, 231, 259,

    268, 341

    Math.sqrt function, 68, 75, 411Math.tan function, 76max-height (CSS), 262maximum, 28, 75, 108max-width (CSS), 262media type, 312, 358meetups, JavaScript, 367memory, 12, 79, 200, 386, 396,

    400, 405mental model, 186Mephistopheles, 314mesh, 209message, 247message box, 27message event, 247meta key, 240metaKey property, 240method, 100, 102, 113, 115method attribute, 301method call, 95, 101methods object, 357micro-optimization, 398, 405Microsoft, 213, 302Microsoft Paint, 331Middle East, graph of, 390mime module, 358MIME type, 312, 358, 363mini application, 325minimalism, 176, 254minimum, 28, 56, 75, 90minimum (exercise), 56, 408minus, 14, 173Miro, Joan, 330mirror, 288, 297, 420mirroring, 286, 287MKCOL method, 364, 424mkdir function, 424modification date, 359modifier key, 240modularity, 302module

    AMD system, 183interface, 177, 180large, 179NPM and, 351purpose of, 176requiring, 351scope for, 177

    module loader, 180, 183, 185, 350

    INDEX 441Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • module object, 182modulo operator, 14Mongolian vowel separator, 171month name (exercise), 187, 414Mosaic, 213motion, 254MOUNTAINS data set, 108, 111, 232mouse, 26, 332, 334, 342, 421

    button, 237, 238, 241cursor, 241

    mouse trail (exercise), 250, 417mousedown event, 238, 241, 332,

    334, 421mousemove event, 242–243, 248,

    334–335, 417mouseout event, 243mouseover event, 243, 338mouseup event, 241, 243, 332, 334moveTo method, 279, 282Mozilla, 213, 303multiple attribute, 322, 323multiple-choice, 316, 321, 322multiplication, 13, 257, 267multiplier function, 49mutability, 64, 65, 105mutation, 412

    Nname attribute, 318, 321namespace, 75, 176, 177, 180, 181namespace pollution, 75, 176, 179naming, 4, 6NaN, 14, 17, 18, 140negation, 15, 17neighbor, 328, 422nerd, 166nesting

    of arrays, 68of expressions, 23, 193of functions, 44, 85, 110of loops, 38, 91, 124, 408of objects, 216, 219in regular expressions, 163of scope, 44

    Netscape, 6, 213network, 207–209, 311, 371new operator, 103newline character, 14, 38, 155, 165,

    169, 421

    nextSibling property, 218node, 216–217node program, 349, 350Node.js

    asynchronous programmingand, 352

    console.log and, 27DELETE method, 359file server example, 361fs module, 353GET method, 358HTTP module, 354long polling and, 368–370module system, 182, 350–351NPM, 177, 351overview, 347–349, 363PUT method, 360stopping script, 355streams and, 356

    node_modules directory, 351–352NodeList type, 218nodeType property, 217, 417, 418nodeValue property, 219nonbreaking space, 171normalizing, 394not a number, 14note-taking example, 325notification, 369NPM, 177, 351–353, 358, 362, 372–373null, 18, 19, 79, 95, 144, 411number

    conversion to, 18, 29immutable types, 65matching with regular expression,

    155, 173notation, 12, 13precision of, 13representation, 12special values, 14

    number field, 336Number function, 29, 36number puzzle example, 51

    Oobject

    creation, 103DOM and, 216global, 77identity, 65

    442 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • immutable, 65instanceof operator, 115looping over, 70as map, 105, 124, 257, 411Math, 75OOP history, 99overview, 59, 102property, 61

    Object prototype, 102, 106, 107object shape, 403Object.create function, 102, 107, 200Object.keys function, 112, 123, 232object-oriented programming, 99–100,

    107–108, 115obstacle, 130, 264–265obstacleAt method, 265offsetHeight property, 225offsetWidth property, 225on method, 356onclick attribute, 212, 236open method, 303–304OpenGL, 277opening tag, 210operator, 13, 15–16, 19, 192, 198, 403optimization

    batching updates, 401benchmarking, 225canvas elements, 337clarity of code, 91compiling, 390, 396profiling, 395pure functions, 55transformations, 297type observation, 402

    option (HTML tag), 316–317, 322,334, 425

    optional, in pattern, 156optional argument, 48, 74, 78options property, 322ordering, 208organization, 175–176outline, 278output, 15, 27, 143, 198, 421overflow, with numbers, 13overflow (CSS), 262overlap, 265overlay, 228overriding, 104, 107, 114, 415overwriting, 360, 365, 375

    Pp (HTML tag), 210, 224package (reserved word), 26package manager, 177package.json file, 352padding (CSS), 261page reload, 246, 315, 319, 325, 426pageX property, 241, 342pageXOffset property, 225pageY property, 241, 342pageYOffset property, 225, 245Palef, Thomas, 254paragraph, 210parallelism, 246, 301, 348–349parameter, 42, 43, 47, 74, 86, 141, 418parent node, 237parentheses

    declaring precedence, 13expressions, 23for loops, 33functions and, 27, 179, 192if statements, 30regular expressions, 157, 159

    160, 170while loops, 31

    parentNode property, 218parse function, 195parseApply function, 194parseExpression function, 193parseINI function, 170parsing, 191–193, 211, 376partial application, 94password, 311, 364, 371password field, 316path

    canvas, 278–280, 282, 335, 419closing, 279filesystem, 350, 357–358, 424URL, 300, 303, 357–358, 369, 372

    pathfinding, 130, 135, 413pathfinding (exercise), 404–405,

    426–427patience, 343pattern, 153–155, 166pausing (exercise), 273, 418pea soup, recipe analogy, 82peanuts, in weresquirrel example,

    71–72percent, 245

    INDEX 443Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • percent sign, 301performance

    canvas, 295, 344compilation and, 200games and, 255JavaScript engine, 389regular expressions and, 162single thread and, 247synchronous functions, 354

    period character, 27, 61, 155, 165,173, 424

    persistence, 325, 368, 384, 386, 425phase, 258–259, 268phi coefficient, 67–68phi function, 68photosynthesis, 130–131, 133physics, 264, 268, 391, 417physics engine, 265pi, 13, 76, 231, 259, 282PI constant, 76picture, 275–276, 285, 295, 332pie chart example, 283–284, 297, 419pipe, 208pipe character, 160, 414pipe method, 358, 360pixel, 225, 231, 276, 285, 291, 295,

    297, 342pixel art, 285pizza, in weresquirrel example, 67–68placeholder, 380, 383plant, 130–131, 133–135, 412Plant type, 133PlantEater type, 133platform game, 253, 273Plauger, P.J., 138player character, 285, 293Player type, 257, 268plus character, 13, 156, 173plus function, 91pointer, 218polling, 235polymorphism, 107–108, 115pop method, 62, 72Popper, Karl, 222port, 208, 299, 354–355pose, 285position, 225position (CSS), 229, 233, 245, 254, 262,

    342, 422

    POST method, 301, 302, 319, 370,384, 426

    postMessage method, 247power example, 42, 48, 50, 200pre (HTML tag), 223precedence, 13, 14, 17, 228predators (exercise), 136, 413predicate function, 88, 96predictability, 186, 399premature optimization, 50, 402preprocessing, 183preventDefault method, 239, 245–246,

    270, 319, 334, 417previousSibling property, 218primitiveMultiply (exercise), 150, 413privacy, 212, 338private (reserved word), 26private property, 127, 151process object, 350profiling, 50, 91, 395, 398program, 2, 23, 29program size, 81–82, 172, 259, 310programming

    difficulty of, 2history of, 4joy of, 3

    programming languagecreating, 191history, 3JavaScript as, 139machine language and, 389Node.js and, 348power of, 5scopes in, 176

    programming stylecomplexity and, 3encapsulation, 259indentation, 33inheritance, 115interfaces, 113loops, 31promises, 362semicolons, 24using underscores, 36, 109whitespace, 32

    progress bar, 244project chapter, 119, 176, 191, 253,

    331, 367

    444 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • promise, 308–310, 313, 324,362–363, 421

    Promise constructor, 308, 313, 421prompt function, 28, 340promptDirection function, 148–149promptInteger function, 144propagation, see event propagationproperty

    adding, 104assignment, 64brace notation, 63console.log, 27deletion, 64DOM objects and, 222global scope and, 77interfaces and, 113methods and, 100model of, 64naming, 127Object.keys function, 112overview, 61, 102, 140own, 106square brackets and, 61testing for, 64

    protected (reserved word), 26protocol, 208, 209, 299–300, 337prototype

    avoidance, 107creating objects from, 102deriving, 114diagram, 104functions and, 102interference, 105Object.prototype, 102overview, 102, 105pollution, 106

    prototype property, 103–104proxy, 371pseudo array, see array-like objectpseudorandom number, 76pseudoselector, 244public (reserved word), 26public space (exercise), 364, 425publishing, 352punch card, 4pure function, 54, 78, 88, 91, 186, 328,

    412, 422push method, 62, 72, 426pushing data, 368

    PUT method, 300–301, 357, 360, 370,375, 385, 425

    Pythagoras, 341, 411

    Qquadratic curve, 280quadraticCurveTo method, 280, 419query string, 301–302, 370, 376, 426querySelector method, 229, 332, 382querySelectorAll method, 229question mark, 17, 156, 165, 301quirks, 213quotation mark, 14, 173quoting

    in JSON, 87of object properties, 63

    quoting style (exercise), 173, 414

    Rrabbit example, 100–103, 105radian, 282, 287radio button, 316, 321radius, 281, 341radix, 11raising exception, 145random number, 76, 123, 133,

    259, 340randomElement function, 123range, 155–157range function, 5, 78, 409ray tracer, 295readability, 5, 36, 54, 144, 176, 308, 310readable stream, 356, 358, 424readAsDataURL method, 339readAsText method, 324readdir function, 354, 359readFile function, 180, 353, 361, 425readFileSync function, 354reading code, 7, 119readStreamAsJSON function, 374–375readStreamAsString function, 424real-time, 235reasoning, 17recipe analogy, 82record, 63, 122recovery, 386rect (SVG tag), 276rectangle, 254, 265, 277, 278, 296

    INDEX 445Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • rectangle tool (exercise), 342, 422recursion, 50, 196, 219, 408, 417,

    425, 426reduce method, 89–90, 92, 95, 108–109reduceAncestors function, 93ReferenceError type, 202RegExp constructor, 153–154, 166regexp golf (exercise), 172registerChange function, 374–375,

    378, 425regular expressions

    alternatives, 160backtracking, 162boundary, 160character categories, 171character sets, 154creation, 153, 166debugging, 166escaping, 154, 155, 166, 414flags, 157, 163, 166, 414global option, 163, 167–168, 223greedy operators, 165grouping, 157, 163internationalization, 170lastIndex property, 167matching, 161, 167methods, 154, 158, 167overview, 153, 154repetition, 156replace method and, 163

    relatedTarget property, 243relative path, 350, 357, 364, 425relative positioning, 229, 230relative URL, 303relativePos function, 334, 422, 423remainder operator, 14, 34, 286, 408,

    417, 419remote access, 357remote procedure call, 310removeChild method, 220removeEventListener method, 236, 418removeItem method, 325rename function, 354rendering, 277repeating key, 239repetition, 52, 156, 162, 166, 248,

    387, 426replace method, 163, 173, 414, 424

    replaceChild method, 220replaceSelection function, 320reproduction, 130, 132, 133, 135, 413repulsion, 391, 393request, 300, 301, 303, 319, 354–355,

    361, 368request function, 355, 356, 363, 424requestAnimationFrame function, 230,

    246, 248, 271, 297, 417require function, 180, 181, 183, 188,

    350, 352RequireJS, 185reserved word, 26, 224reset, 425resize, 339resolution, 350resource, 209, 300, 301, 311, 337,

    357, 374response, 300, 301, 306, 354, 358, 360,

    362, 424responseText property, 303, 304responseXML property, 304responsiveness, 235, 347, 390restore method, 288, 289result property, 324return keyword, 42, 47, 103, 408, 411return value, 28, 42, 144, 352, 410reuse, 54, 177, 351reverse method, 78reverse proxy, 371reversing (exercise), 78, 409rgb (CSS), 261, 343, 423right-aligning, 112, 232robustness, 369root, 217rotate method, 287, 289rotation, 296, 419rounding, 76, 143, 265–266, 281, 292router, 365, 369, 372Router type, 372row, 232rowHeights function, 108RTextCell type, 114rules (CSS), 227–228run function, 198runAnimation function, 271, 273runGame function, 272–273, 418runLayout function, 394

    446 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • runLevel function, 271, 273running code, 7run-time error, 139, 141, 142, 144,

    150, 416

    SSafari, 213sandbox, 59, 212, 215, 305, 338save link, 337save method, 288–289saving, 332scalar replacement of aggregates,

    396, 399scale method, 286, 288scaling, 260, 285–286, 293, 420scheduling, 348scientific notation, 13, 173scope, 43, 44, 77, 125, 176, 177,

    181, 416script (HTML tag), 211–212, 246, 380scroll event, 244, 248scrolling, 239, 244–245, 263, 270, 291search method, 167searching, 161, 162, 167, 219, 344, 404section, 169, 170Secure HTTP, see HTTPSsecurity, 212–213, 305, 311, 323,

    338, 358SecurityError type, 338, 423select (HTML tag), 316–317, 322, 325,

    332, 334, 425selected attribute, 322selection, 319, 334selectionEnd property, 319selectionStart property, 319selector, 229self variable, 125self-closing tag, 210semicolon, 24, 33, 226send method, 303, 304sequence, 156sequence (exercise), 117, 412serialization, 87server, 208, 299–301, 306, 347,

    354–357session, 327, 338sessionStorage object, 327set, 155, 217

    setAttribute method, 222, 224setInterval function, 248, 285, 341setItem method, 325, 326setRequestHeader method, 304, 312setter, 113setTimeout function, 248, 378shape, 275, 279, 281, 284, 296shapes (exercise), 296, 419shared property, 103, 104, 114SHIFT key, 240shift method, 72shiftKey property, 240short-circuit evaluation, 20, 51,

    197, 411SICP, 191side effect, 24, 28, 42, 54, 220, 278sign, 13, 173, 414sign bit, 13signal, 11simplicity, 186, 200simulation, 119, 123, 126, 128, 130,

    391, 417sine, 76, 231, 259, 268single-quote character, 14, 173, 212size attribute, 322skill, 332skill-sharing project, 367–369, 372,

    379, 387skipSpace function, 194, 202slash character, 14, 36, 153, 154, 165,

    303, 364, 424slice method, 73, 74, 221, 324, 415sloppy programming, 127, 249smooth animation, 230SMTP, 208some method, 96, 373, 426sorting, 217source property, 167special form, 191, 196special return value, 144specialForms object, 196specificity, 228speed, 297, 420spell-check example, 186spiral, 296, 419splice method, 377split method, 110, 351spray paint tool, 340spring, 391, 393

    INDEX 447Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • sprite, 285, 292–293square, 29, 42square brackets, 61, 69, 155, 409square example, 45square root, 68, 75, 411src attribute, 210, 211stability, 135, 136, 177, 413stack, see call stackstack overflow, 47, 50, 56, 409stack trace, 145, 149, 361staged compilation, 390standard, 6, 26, 46, 170, 207, 336standard environment, 26standard output, 349, 357standards, 213star, 296, 419Star Trek, 280starvation, 135, 413stat function, 354, 359, 363state, 24, 32–34, 289, 412, 418statement, 23, 24, 29, 31, 33, 42, 179static (reserved word), 26static file, 369, 373static typing, 139, 402Stats type, 359status code, 300, 303, 306–307,

    350, 358status property, 303statusText property, 303stdout property, 357stopPropagation method, 238stream, 208, 355, 356, 358, 360StretchCell (exercise), 117, 412strict mode, 140string

    immutable types, 65indexing, 56, 73, 74, 157methods, 74, 110, 158, 240notation, 14overview, 14, 60properties, 62, 73searching, 74

    String function, 29, 107stroke method, 279, 280strokeRect method, 278, 420strokeStyle property, 278, 332, 335, 337strokeText method, 284stroking, 278, 284, 296strong (HTML tag), 223, 224, 226

    structure, 176, 210, 215structure sharing, 79style, 226style (HTML tag), 227–228style attribute, 226–228, 260style sheet, see CSSsubmit, 315–316, 318, 319submit event, 319, 339, 380, 385, 425substitution, 54subtraction, 14, 117suggestion, 328sum function, 5, 78summing (exercise), 78, 409summing example, 4, 81, 89, 199survey, 283Sussman, Gerald, 190SVG, 275–278, 295switch keyword, 35synchronization, 371, 381, 382, 385synchronous I/O, 183, 304, 348,

    354, 420syntax

    arithmetic, 13brace notation, 63conditional execution, 29, 35declaration notation, 45error handling, 145expressions, 23functions, 42loops, 31, 33namespace function, 179numbers, 12, 173reserved words, 26statements, 24strict mode, 140strings, 14variables, 24

    syntax highlighting example, 223–224syntax tree, 192–195, 216–217SyntaxError type, 194

    Ttab character, 15, 33TAB key, 318tabbed interface (exercise), 251, 418tabindex attribute, 241, 318table, 67–69, 108, 232, 261table (HTML tag), 232, 254, 261, 422

    448 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • table example, 108–111, 114, 232, 416tableFor function, 68tag, 209–210, 215, 228. See also names

    of specific tagstagName property, 232tainting, 338talk, 367–368, 374–376, 382talksAbout function, 219tampering, 311tangent, 76target property, 238, 243, 321, 421task management example, 72taste, 175, 188TCP, 208, 299, 369td (HTML tag), 232template, 380, 382, 387, 426template-repeat attribute, 387, 426tentacle (analogy), 25, 64, 66ternary operator, 17, 20test method, 154test suite, 141–142testing framework, 142text, 421text field, 245, 250, 316–317, 319–320,

    328, 339text input, 28text node, 217, 219, 221, 332, 418text wrapping, 295text-align (CSS), 232textAlign property, 284, 419textarea (HTML tag), 248, 316, 319,

    320, 325, 327, 425textBaseline property, 284, 419TextCell type, 111, 114textContent property, 223, 421TEXT_NODE code, 217, 418th (HTML tag), 232then method, 309–310, 421theory, 143this, 62, 101, 103, 125–126, 131,

    140, 179thread, 247, 348, 349throw keyword, 145, 148, 150, 361, 413Tiger type, 136tile, 292time, 155, 158, 381time field, 336timeline, 211, 230, 235, 246, 348

    timeout, 247, 369, 370, 378times method, 257timing, 394title, 379title (HTML tag), 210, 211toDataURL method, 337–338, 342toLowerCase method, 62, 232tool, 153, 172, 332, 334, 340, 342tools object, 334top (CSS), 229–231, 233, 342top-level scope, see global scopetoString method, 102, 104, 105,

    107, 120toUpperCase method, 62, 232, 356tr (HTML tag), 232trackDrag function, 334, 341, 422trackKeys function, 270, 273transform (CSS), 275transformation, 286–289, 297, 419translate method, 287, 288Transmission Control Protocol,

    see TCPtransparent, 277, 285, 343transpilation, 200trapezoid, 296, 419traversal, 161tree, 92, 102, 192, 217treeGraph function, 392trial and error, 269, 281triangle (exercise), 37, 407trigonometry, 76, 231trim method, 74true, 16trust, 212try keyword, 145–146, 307–308, 338,

    361, 413, 421Turkish, and censored keyboard, 250turn, 119, 120Twitter, 300type, 12, 15, 115, 139type attribute, 316, 319type coercion, 18–19, 29type observation, 390, 397, 402type property, 192, 237typeof operator, 15, 79, 410typing, 240, 248, 250typo, 139

    INDEX 449Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • Uunary operator, 15uncaught exception, 147, 308, 361undefined, 18–19, 26, 42, 47, 63,

    140, 144underline, 226underscore character, 25, 36, 109,

    127, 166Unicode, 16, 155, 170–171, 240, 351unicycling, 367uniformity, 192, 341uniqueness, 228unit (CSS), 231, 245Universal Resource Locator, see URLUnix, 359, 361Unix time, 159, 371unlink function, 354unshift method, 72UnterlinedCell type, 112unwinding the stack, 145upcasing server example, 356upgrading, 177upload, 323URL, 209, 303, 311, 337, 358URL encoding, 301, 426URL field, 336url module, 358, 376urlToPath function, 358, 364use strict, 140user experience, 235, 306, 318, 342,

    368, 381user interface, 147users’ group, 367UTF-8, 353, 354

    Vvalidation, 144, 150, 319, 375, 377value, 12value attribute, 316, 319, 322var keyword, 24, 26, 43, 140variable

    assignment, 25, 43, 45best practices, 200debugging, 147definition, 24, 202, 416functions as, 42, 45global, 43, 140, 180, 273, 350for loop, 33model of, 25, 66

    naming, 25–27, 35, 43, 52, 76, 141overview, 32from parameter, 43, 49persistence, 325scope and, 202

    variadic function, 75vector (exercise), 117, 411vector graphics, 284Vector type, 117, 120, 141, 257, 420verbosity, 332, 349, 361version, 180, 210, 300version control, 176View type, 122, 127, 130viewport, 242, 262, 264, 290–291, 294virus, 212vocabulary, 41, 82, 91, 94void operator, 26volatile data storage, 12

    Wwalk, 344walking, 293wall, 120, 124, 255wall following, 129, 413Wall type, 124WallFollower type, 129wave, 259, 267, 268Web, see World Wide Webweb application, 6, 325, 331, 387web browser, see browserweb programming, 213web sockets, 369web worker, 247WebDAV, 364webgl (canvas context), 277website, 212–213, 301, 305, 364, 367weekday example, 177, 181, 183, 187weekend project, 365Weizenbaum, Joseph, 2weresquirrel example, 60

    analysis, 70–72correlation in, 66–68

    computing, 68–69objects, 63–65

    as maps, 69–70which property, 237while loop, 5, 31, 33, 53, 168, 267whitespace, 32, 35, 74, 155, 171, 219,

    416, 418

    450 INDEX Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

  • Why’s Poignant Guide to Ruby, 22width (CSS), 342window, 236, 237, 243, 246, 350window variable, 77Windows, 364with statement, 141withContext function, 146–147word boundary, 160word character, 155, 160, 170work list, 423workbench (exercise), 327, 421world, 119, 120, 253World type, 12–124, 126–127, 130World Wide Web, 6, 87, 183, 207, 209,

    212–213, 299writable stream, 355–358write method, 355, 356writeFile function, 353, 356, 425writeHead method, 354writing code, 7, 119WWW, see World Wide Web

    XXML, 218, 276, 302, 304, 305XML namespace, 276XMLHttpRequest, 302–304, 306, 312,

    319, 425xmlns attribute, 276

    Yyield (reserved word), 26Yuan-Ma, 10, 346

    ZZawinski, Jamie, 152zero-based counting, 56, 61, 159zeroPad function, 54zigzag shape, 419zooming, 295

    INDEX 451Eloquent JavaScript, 2nd Edition © 2014 Marijn Haverbeke

    9781593275846_ONLINE 4539781593275846_ONLINE 4549781593275846_ONLINE 4559781593275846_ONLINE 4569781593275846_ONLINE 4579781593275846_ONLINE 4589781593275846_ONLINE 4599781593275846_ONLINE 4609781593275846_ONLINE 4619781593275846_ONLINE 4629781593275846_ONLINE 4639781593275846_ONLINE 4649781593275846_ONLINE 4659781593275846_ONLINE 4669781593275846_ONLINE 4679781593275846_ONLINE 4689781593275846_ONLINE 4699781593275846_ONLINE 4709781593275846_ONLINE 4719781593275846_ONLINE 4729781593275846_ONLINE 4739781593275846_ONLINE 4749781593275846_ONLINE 475