"" (quotation marks), 12, 160–161
/* */ comments, 72
/= operator, 178
; (semicolon), 11
|| operator, 42
+ operator, 163
= = = operator, 240–241, 245, 246
-= operator, 178
!= operator, 42
%= operator, 178
&& operator, 42
**= operator, 178
*= operator, 178
[] (brackets), 144
{} (brackets), 26
< operator, 42
<= operator, 42
> operator, 42
>= operator, 42
absolute value, 185
abstraction, objects as, 138–139
accessing
child objects, 303
console, 337
accessor properties, 188
data properties, compared, 188–190
addEventListener function, 346–348, 362–363
adding
class values, 293
alert function, 11–12, 119–120, 340
altKey property, 384
animation with requestAnimationFrame function, 80–81
appending child objects to parent, 309–313
for callback functions, 156–157
array literal notation, 145
in JSON, 256
values
counting, 146
finding, 150
arrow key presses, 386
async attribute, 400
attribute selectors, 276
bigint type, 137
Boolean object, 238
boolean type, 237
strict equality/inequality operators, 240–241
bracket notation, 199
brackets ([]), 144
brackets ({}), 26
browser mouse position, 376–377
browsers
console. See console
developer tools. See developer tools
buttons property, 378
functional programming, 157–158
case (of strings), changing, 168, 191
changing
attribute values in DOM, 286–288
characters in strings
charAt method, 162
child objects, 206–207, 299–300
accessing, 303
checking existence, 303
childNodes property, 313
children property, 301–302, 313
choosing document structure, 114–116
class keyword, 222
class values
adding, 293
checking existence, 294
toggling, 294
constructor functions, 224–226
creating, 222
functions in, 229
add method, 293
contains method, 294
toggle method, 294
clearInterval function, 80
clearTimeout function, 78
cloning HTML elements, 315–319
combining
strings, 163
multi-line comments, 72
concatenating strings, 163
condition, for loops, 62
strict equality/inequality operators, 240–241
accessing, 337
Console API, 125
inspecting objects, 338
log method
logging messages, 340
scope in, 339
Console API, 125
console.log function, 340
constructor functions, 171, 224–226
constructor keyword, 224
contains method, 294
continue keyword, 64
converting strings to numbers, 179
counting array values, 146
createElement method, 306
properties
ctrlKey property, 384
accessor properties, compared, 188–190
dealWithKeyboard event handler, 383–384
declaring variables, 16, 18–20, 86–87, 90
decrementing
default actions, preventing, 366
defining functions, 24
delays with setTimeout function, 78
delete keyword, 201
console. See console
DOM view, View Source, compared, 326–331
displaying
Document Object Model. See DOM (Document Object Model)
document property, 299
document structure, 105–116, 262–266
DOM hierarchy, compared, 297–298
JavaScript within HTML document, 109–110
JavaScript within JavaScript file, 110–113
document.documentElement property, 299
document.write function, 57
DOM (Document Object Model), 267–271
events within
HTML elements
accessing child elements, 303
checking child existence, 303
document structure, compared, 297–298
parent/sibling properties, 301
objects
window object, 269
DOM view, View Source, compared, 326–331
DOMContentLoaded event, 347, 395–396
elements (HTML)
querySelector function, 275–277
querySelectorAll function, 275–277
nodes, compared, 319
parents/siblings/children, 299–303
styles. See styles
Event Bubbling Phase, 362
Event Capturing Phase, 361
for multiple elements, 405–413
with parent/child relationship, 409–412
Event type, 352
handling. See event handlers
arrow key presses, 386
Keyboard event properties, 384
list of, 382
listening for, 383
particular key presses, 385
list of, 347
listening for, 346–348, 363–364
list of, 368
mouseenter event, 371
MouseEvent properties, 375–378
mouseleave event, 371
mousemove event, 373
DOMContentLoaded event, 395–396
preventing default actions, 366
exiting functions early, 34
expressions, 40
operators
incrementing/decrementing, 177–179
order of operation, 177
filtering array values, 154–155
find method, 150
findIndex method, 150
finding
array values, 150
querySelector function, 275–277
querySelectorAll function, 275–277
condition, 62
continue keyword, 64
iterations, 63
non-numeric values in, 65
starting point, 61
function keyword, 25
functional programming, 157–158
functional programming, 157–158
constructor functions, 171, 224–226
defining, 24
event handlers. See event handlers
exiting early, 34
uppercase generator example, 191
local scope, 86
purpose of, 23
returning data, 33
getAttribute function, 276, 286
uppercase generator example, 191
handling events. See event handlers
hexadecimal numbers, 179
hoisting variables, 91
elements
parents/siblings/children, 299–303
styles. See styles
async attribute, 400
html element, 298
switch statements, compared, 51–54
includes method, 150
incrementing, operators for, 177–179
index positions, 162
Infinity value, 180
inheritance, 212
initializing variables, 16, 18–20, 86–87
in-scope, 89
insertBefore function, 310–312
inspecting
DOM (Document Object Model), 326–331
objects, 338
iterations, for loops, 63
skipping, 64
JavaScript
within JavaScript file, 110–113
requirements, 8
styles and
naming CSS properties, 291–292
purpose of, 290
setting CSS properties, 290–291
JSON (JavaScript Object Notation), 247–259
data
parsing, 259
writing, 259
object literal syntax, 248–251
objects
property names, 252
JSON.parse method, 259
Keyboard event properties, 384
arrow key presses, 386
Keyboard event properties, 384
list of, 382
listening for, 383
particular key presses, 385
keysPressed event handler, 387–388
keysReleased event handler, 388
let keyword, 16, 18–19, 88, 90
listening for events, 346–348, 363–364
mouseenter event, 371
MouseEvent properties, 375–378
mouseleave event, 371
mousemove event, 373
local scope, 86
log method
logging example (getters/setters), 191–192
logging in console, 340
condition, 62
continue keyword, 64
iterations, 63
non-numeric values in, 65
starting point, 61
while loops, 66
match method, 167
Math object, 140, 170, 180–185
absolute value, 185
random numbers, 185
rounding numbers, 182
trigonometric functions, 183–184
Math.abs() function, 185
Math.acos() function, 184
Math.asin() function, 184
Math.atan() function, 184
Math.ceil() function, 183
Math.cos() function, 184
Math.E constant, 181
Math.exp() function, 184
Math.floor() function, 183
Math.LN2 constant, 181
Math.LN10 constant, 181
Math.LOG2E constant, 181
Math.LOG10E constant, 181
Math.pow() function, 184
Math.random() function, 185
Math.round() function, 183
Math.sin() function, 184
Math.sqrt() function, 184
Math.SQRT1_2 constant, 181
Math.SQRT2 constant, 181
Math.tan() function, 184
metaKey property, 384
modifying
list of, 368
mouseenter event, 371
MouseEvent properties, 375–378
browser mouse position, 376–377
global mouse position, 375–376
mouseleave event, 371
mousemove event, 373
mouseenter event, 371
MouseEvent properties, 375–378
browser mouse position, 376–377
global mouse position, 375–376
mouseleave event, 371
multi-line comments, 72
multiple elements, event handlers for, 405–413
naming
NaN keyword, 180
navigating DOM hierarchy, 297–304
accessing child elements, 303
checking child existence, 303
document structure, compared, 297–298
parent/sibling properties, 301
nested functions
nextSibling property, 301
elements (HTML), compared, 319
non-numeric values in for loops, 65
as 64-bit floating point, 176
absolute value, 185
basic usage, 176
converting strings to, 179
Infinity value, 180
in JSON, 254
NaN keyword, 180
octal/hexadecimal, 179
operators
incrementing/decrementing, 177–179
order of operation, 177
random, 185
rounding, 182
object literal syntax, 197, 248–251
objects, 138, 195–211. See also classes; names of specific objects
constructor functions, 171
creating, 197, 205–208, 222–224
DOM
window object, 269
shuffling arrays example, 213–219
inspecting, 338
JSON
property names, 252
list of, 140
Object type, 196
properties, 196
prototypical inheritance model, 212
octal numbers, 179
operators
incrementing/decrementing, 177–179
order of operation, 177
strict equality/inequality, 240–241
order of operation, 177
out-of-scope, 89
DOMContentLoaded event, 395–396
parent objects, 206–207, 299–300
properties, 301
parentNode property, 301
parseInt function, 179
parsing JSON data, 259
preventDefault function, 366, 374–375, 389
previousSibling property, 301
primitives, 138. See also names of specific types
properties, 196
in CSS
parent/sibling properties, 301
for Event type, 352
in JSON
names, 252
for Keyboard event, 384
browser mouse position, 376–377
global mouse position, 375–376
prototype chain, 201–204, 207–208, 214–219
prototypical inheritance model, 212
querySelector function, 275–277
random numbers, 185
raw text, parsing, 259
recursively walking DOM hierarchy, 303–304
referencing JavaScript files, 111–113
remove method, 315
removeEventListener function, 352–353
removing
requestAnimationFrame function, 80–81
returning data
from functions, 33
rounding numbers, 182
scope. See variable scope
async attribute, 400
JavaScript within HTML document, 109–110
JavaScript within JavaScript file, 110–113
scroll event, 347
semicolon (;), 11
uppercase generator example, 191
setTimeout function, 78
sharing variables in functions, 98–104
shiftKey property, 384
properties, 301
slice method, 164
starting point, for loops, 61
statements, 11
stepping through code, 334–336
stopPropagation method, 364–366, 412
strict equality/inequality operators, 240–241
characters
combining, 163
converting to numbers, 179
in JSON, 253
substrings, extracting, 164–165
style object, 290
JavaScript and
naming CSS properties, 291–292
purpose of, 290
setting CSS properties, 290–291
rules, 289
substrings, extracting, 164–165
super keyword, 233
if/else statements, compared, 51–54
symbol type, 137
text values, changing in DOM, 284–285
requestAnimationFrame function, 80–81
setTimeout function, 78
toggling class values, 294
toLowerCase method, 168
toUpperCase method, 168
trigonometric functions, 183–184
types, 133–141. See also names of specific types
list of, 137
constructor functions, 171
creating, 197, 205–208, 222–224
list of, 140
Object type, 196
properties, 196
prototypical inheritance model, 212
primitives, 138
UI development with setTimeout function, 78
undefined type, 137, 201, 244–246
uppercase generator example (getters/setters), 191
validation example (getters/setters), 192–193
in arrays
counting, 146
finding, 150
arrays, 256
null, 256
numbers, 254
strings, 253
null, 244
var keyword, 90
in console, 339
in-scope, 89
local scope, 86
out-of-scope, 89
declaring, 16, 18–20, 86–87, 90
hoisting, 91
walking DOM hierarchy, 303–304
web pages. See document structure
which property, 378
while loops, 66
whitespace in comments, 74
window property, 299
writing
JSON data, 259
18.116.36.221