Index

Symbols

- - operator, 178179

"" (quotation marks), 12, 160161

// comments, 7172

/* */ comments, 72

/= operator, 178

; (semicolon), 11

|| operator, 42

+ operator, 163

++ operator, 178179

+= operator, 163, 178

= = operator, 42, 246

= = = operator, 240241, 245, 246

-= operator, 178

!= = operator, 240241

!= operator, 42

%= operator, 178

&& operator, 42

() (parentheses), 2526

**= operator, 178

*= operator, 178

[] (brackets), 144

{} (brackets), 26

< operator, 42

<= operator, 42

> operator, 42

>= operator, 42

A

absolute value, 185

abstraction, objects as, 138139

accessing

array values, 145146

child objects, 303

console, 337

developer tools, 324326

string characters, 161162

accessor properties, 188

data properties, compared, 188190

addEventListener function, 346348, 362363

adding

array values, 147148

class values, 293

properties, 197200

alert function, 1112, 119120, 340

altKey property, 384

animation with requestAnimationFrame function, 8081

appendChild method, 309310

appending child objects to parent, 309313

arguments, 2832

for callback functions, 156157

for event handlers, 351352

array literal notation, 145

Array object, 140, 170

arrays, 143158

creating, 144145

in JSON, 256

merging, 150151

shuffling, 213219

values

accessing, 145146

adding, 147148

combining, 155157

counting, 146

filtering, 154155

finding, 150

modifying, 151153

removing, 149150

arrow key presses, 386

async attribute, 400

attribute selectors, 276

attribute values, changing in DOM, 286288

B

best practices, 7375

bigint type, 137

block scope, 8790

Boolean function, 238240

Boolean logic, 45, 237241

Boolean function, 238240

Boolean object, 238

boolean type, 237

in JSON, 254255

strict equality/inequality operators, 240241

Boolean object, 140, 170, 238

boolean type, 137, 170, 237

bracket notation, 199

brackets ([]), 144

brackets ({}), 26

break keyword, 50, 6364

breakpoints, 332, 337

browser mouse position, 376377

browsers

console. See console

developer tools. See developer tools

bubbling events, 355366

phases, 361364

stopping propagation, 364366

usage example, 356360

button property, 377378

buttons property, 378

C

callback functions, 154, 155

arguments, 156157

functional programming, 157158

calling functions, 24, 27

capturing events, 355366

phases, 361364

stopping propagation, 364366

usage example, 356360

case (of strings), changing, 168, 191

case blocks, 4851

changing

attribute values in DOM, 286288

case of strings, 168, 191

text values in DOM, 284285

variable values, 1920

characters in strings

accessing, 161162

finding, 166167

charAt method, 162

charCode property, 384, 385

child objects, 206207, 299300

accessing, 303

appending to parent, 309313

checking existence, 303

event handling, 409412

properties, 301302

removing from parent, 314315

childNodes property, 313

children property, 301302, 313

choosing document structure, 114116

class keyword, 222

class values

adding, 293

checking existence, 294

removing, 293294

toggling, 294

classes, 221235

constructor functions, 224226

creating, 222

elements of, 226229

extending objects, 229235

functions in, 229

classList API, 292294

add method, 293

contains method, 294

remove method, 293294

toggle method, 294

className property, 287288

clearInterval function, 80

clearTimeout function, 78

click event, 347, 368370

clientX property, 376377

clientY property, 376377

cloneNode method, 315319

cloning HTML elements, 315319

closures, 93104

nested functions, 9497

sharing variables via, 98104

combining

array values, 155157

strings, 163

comments, 6975

best practices, 7375

JSDoc comments, 7273

multi-line comments, 72

purpose of, 7071

single line comments, 7172

concat method, 150151, 163

concatenating strings, 163

condition, for loops, 62

conditional statements, 3754

complex expressions, 4445

else if keyword, 4647

if statements, 4546

if/else statements, 3941

operators, 4144

strict equality/inequality operators, 240241

switch statements, 4754

which to use, 5354

console, 119130, 337340

accessing, 337

Console API, 125

displaying, 121124

inspecting objects, 338

log method

predefined text in, 125127

values in, 127128

logging messages, 340

purpose of, 120121

scope in, 339

warnings and errors, 128130

Console API, 125

console.log function, 340

const keyword, 1920, 88

constants, 181182

constructor functions, 171, 224226

constructor keyword, 224

contains method, 294

contextmenu event, 374375

continue keyword, 64

converting strings to numbers, 179

counting array values, 146

createElement method, 306

CSS, 56

properties

naming, 291292

setting, 290291

purpose of, 264265

selector syntax, 276277

ctrlKey property, 384

D

data properties, 187188

accessor properties, compared, 188190

Date object, 140, 170

dblclick event, 347, 368370

dealWithKeyboard event handler, 383384

debugging JavaScript, 331337

declaring variables, 16, 1820, 8687, 90

decrementing

for loops, 6465

operators for, 177179

default actions, preventing, 366

default blocks, 5051

defer attribute, 400401

defining functions, 24

delays with setTimeout function, 78

delete keyword, 201

detail property, 378379

developer tools, 323340

accessing, 324326

console. See console

debugging JavaScript, 331337

DOM view, View Source, compared, 326331

displaying

console, 121124

warnings and errors, 128130

document object, 269271, 298

Document Object Model. See DOM (Document Object Model)

document property, 299

document structure, 105116, 262266

choosing, 114116

CSS in, 264265

DOM hierarchy, compared, 297298

HTML in, 262264

JavaScript in, 265266

JavaScript within HTML document, 109110

JavaScript within JavaScript file, 110113

document.documentElement property, 299

document.write function, 57

DOM (Document Object Model), 267271

events within

phases, 361364

usage example, 356360

HTML elements

cloning, 315319

creating, 306312

finding, 273277

modifying, 279288

as objects, 280282

removing, 314315

inspecting, 326331

navigating hierarchy, 297304

accessing child elements, 303

checking child existence, 303

child properties, 301302

document structure, compared, 297298

parent/sibling properties, 301

properties for, 298300

recursively walking, 303304

nodes, 267268

objects

document object, 269271

window object, 269

script placement in, 397400

DOM view, View Source, compared, 326331

DOMContentLoaded event, 347, 395396

DOMMouseScroll event, 347, 378379

dot notation, 197199

do.while loops, 6667

E

elements (HTML)

cloning, 315319

creating, 306312

finding in DOM, 273277

querySelector function, 275277

querySelectorAll function, 275277

modifying in DOM, 279288

attribute values, 286288

text values, 284285

nodes, compared, 319

as objects, 280282

parents/siblings/children, 299303

removing, 314315

styles. See styles

else if keyword, 4647

error method, 128130

Event Bubbling Phase, 362

Event Capturing Phase, 361

event handlers, 347348

arguments, 351352

for multiple elements, 405413

with parent/child relationship, 409412

what not to do, 408409

usage example, 348351

event targets, 359, 411

Event type, 352

events, 343353

bubbling, 355366

phases, 361364

stopping propagation, 364366

usage example, 356360

capturing, 355366

phases, 361364

stopping propagation, 364366

usage example, 356360

handling. See event handlers

keyboard events, 381389

arrow key presses, 386

Keyboard event properties, 384

list of, 382

listening for, 383

multiple key presses, 386389

particular key presses, 385

list of, 347

listening for, 346348, 363364

mouse events, 367379

click event, 368370

contextmenu event, 374375

dblclick event, 368370

DOMMouseScroll event, 378379

list of, 368

mousedown event, 372373

mouseenter event, 371

MouseEvent properties, 375378

mouseleave event, 371

mousemove event, 373

mouseout event, 370371

mouseover event, 370371

mouseup event, 372373

mousewheel event, 378379

page load events, 391396

DOMContentLoaded event, 395396

load event, 395396

stages of page loads, 392395

preventing default actions, 366

purpose of, 344345

removing listeners, 352353

usage example, 348351

exiting functions early, 34

exponents, 184185

expressions, 40

complex, 4445

operators

conditional, 4144

incrementing/decrementing, 177179

order of operation, 177

extending objects, 213220

with classes, 229235

controversy around, 219220

shuffling arrays example, 213219

extends keyword, 231232

extracting substrings, 164165

F

filter method, 150, 154155

filtering array values, 154155

find method, 150

findIndex method, 150

finding

array values, 150

HTML elements in DOM, 273277

querySelector function, 275277

querySelectorAll function, 275277

string characters, 166167

firstChild property, 301302

for loops, 5765

break keyword, 6364

condition, 62

continue keyword, 64

decrementing, 6465

iterations, 63

non-numeric values in, 65

starting point, 61

step region, 6162

function keyword, 25

Function object, 140, 170

functional programming, 157158

functions, 1112, 2134

arguments, 2832

Boolean function, 238240

callback functions, 154155

arguments, 156157

functional programming, 157158

calling, 24, 27

in classes, 226229

constructor functions, 171, 224226

defining, 24

event handlers. See event handlers

exiting early, 34

getters/setters, 187193

basic usage, 190191

logging example, 191192

uppercase generator example, 191

validation example, 192193

local scope, 86

nested functions, 9497

purpose of, 23

returning data, 33

sharing variables in, 98104

trigonometric functions, 183184

G

getAttribute function, 276, 286

getters, 187193

basic usage, 190191

in classes, 226229

logging example, 191192

uppercase generator example, 191

validation example, 192193

global mouse position, 375376

global scope, 8486

H

handling events. See event handlers

Hello, World! 812

hexadecimal numbers, 179

hoisting variables, 91

HTML, 56

elements

cloning, 315319

creating, 306312

finding, 273277

modifying, 279288

as objects, 280282

parents/siblings/children, 299303

removing, 314315

styles. See styles

JavaScript within, 109110

purpose of, 262264

script tag, 1011

async attribute, 400

defer attribute, 400401

placement of, 113, 397400

HTML documents, writing, 811

html element, 298

I

id property, 287288

if statements, 4546

if/else statements, 3941

else if keyword, 4647

operators, 4144

switch statements, compared, 5154

includes method, 150

incrementing, operators for, 177179

index positions, 162

indexOf method, 150, 166167

Infinity value, 180

inheritance, 212

initializing variables, 16, 1820, 8687

in-scope, 89

insertAfter function, 312313

insertBefore function, 310312

inspecting

DOM (Document Object Model), 326331

objects, 338

iterations, for loops, 63

skipping, 64

J

JavaScript

debugging, 331337

document structure, 105116

choosing, 114116

within HTML document, 109110

within JavaScript file, 110113

explained, 78

Hello, World! 812

purpose of, 265266

requirements, 8

styles and

classList API, 292294

naming CSS properties, 291292

purpose of, 290

setting CSS properties, 290291

JavaScript files, 110113

referencing, 111113

structure of, 110111

when to use, 114116

JSDoc comments, 7273

JSON (JavaScript Object Notation), 247259

data

parsing, 259

reading, 257258

writing, 259

object literal syntax, 248251

objects

property names, 252

values, 253256

JSON.parse method, 259

K

Keyboard event properties, 384

keyboard events, 381389

arrow key presses, 386

Keyboard event properties, 384

list of, 382

listening for, 383

multiple key presses, 386389

particular key presses, 385

keyCode property, 384385

keydown event, 347, 382383

keypress event, 382383, 385

keysPressed event handler, 387388

keysReleased event handler, 388

keyup event, 347, 382383

L

lastChild property, 301302

lastIndexOf method, 150, 167

let keyword, 16, 1819, 88, 90

listening for events, 346348, 363364

click event, 368370

contextmenu event, 374375

dblclick event, 368370

DOMMouseScroll event, 378379

keyboard events, 383, 385389

mousedown event, 372373

mouseenter event, 371

MouseEvent properties, 375378

mouseleave event, 371

mousemove event, 373

mouseout event, 370371

mouseover event, 370371

mouseup event, 372373

mousewheel event, 378379

on multiple elements, 405413

page load events, 395396

load event, 347, 395396

local scope, 86

log method

predefined text in, 125127

values in, 127128

logging example (getters/setters), 191192

logging in console, 340

loops, 5567

do.while loops, 6667

for loops, 5765

break keyword, 6364

condition, 62

continue keyword, 64

decrementing, 6465

iterations, 63

non-numeric values in, 65

starting point, 61

step region, 6162

setInterval function, 7980

while loops, 66

M

map method, 152153

match method, 167

Math object, 140, 170, 180185

absolute value, 185

constants, 181182

powers/square roots, 184185

random numbers, 185

rounding numbers, 182

trigonometric functions, 183184

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.PI constant, 181, 182

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

merging arrays, 150151

metaKey property, 384

modifying

array values, 151153

HTML elements in DOM, 279288

attribute values, 286288

text values, 284285

mouse events, 367379

click event, 368370

contextmenu event, 374375

dblclick event, 368370

DOMMouseScroll event, 378379

list of, 368

mousedown event, 372373

mouseenter event, 371

MouseEvent properties, 375378

browser mouse position, 376377

button clicked, 377378

global mouse position, 375376

mouseleave event, 371

mousemove event, 373

mouseout event, 370371

mouseover event, 370371

mouseup event, 372373

mousewheel event, 378379

mousedown event, 372373

mouseenter event, 371

MouseEvent properties, 375378

browser mouse position, 376377

button clicked, 377378

global mouse position, 375376

mouseleave event, 371

mousemove event, 347, 373

mouseout event, 347, 370371

mouseover event, 347, 370371

mouseup event, 372373

mousewheel event, 378379

multi-line comments, 72

multiple elements, event handlers for, 405413

with parent/child relationship, 409412

what not to do, 408409

multiple key presses, 386389

N

naming

CSS properties, 291292

variables, 1718

NaN keyword, 180

navigating DOM hierarchy, 297304

accessing child elements, 303

checking child existence, 303

child properties, 301302

document structure, compared, 297298

parent/sibling properties, 301

properties for, 298300

recursively walking, 303304

nested functions

explained, 9497

sharing variables in, 98104

nesting objects, 199200

new keyword, 222224

nextSibling property, 301

nodes, 267268

elements (HTML), compared, 319

non-numeric values in for loops, 65

null type, 137, 244, 246, 256

Number object, 140, 170

number type, 137, 170

numbers, 175185

as 64-bit floating point, 176

absolute value, 185

basic usage, 176

constants, 181182

converting strings to, 179

Infinity value, 180

in JSON, 254

NaN keyword, 180

octal/hexadecimal, 179

operators

incrementing/decrementing, 177179

order of operation, 177

powers/square roots, 184185

random, 185

rounding, 182

trigonometric functions, 183184

O

object literal syntax, 197, 248251

Object type, 137, 196, 203

objects, 138, 195211. See also classes; names of specific objects

as abstraction, 138139

constructor functions, 171

creating, 197, 205208, 222224

DOM

document object, 269271

window object, 269

DOM elements as, 280282

extending, 213220

with classes, 229235

controversy around, 219220

shuffling arrays example, 213219

inspecting, 338

JSON

property names, 252

values, 253256

list of, 140

nesting, 199200

Object type, 196

parent/child objects, 206207

primitives as, 141, 169173

properties, 196

adding, 197200

removing, 200201

prototype chain, 201204

prototypical inheritance model, 212

this keyword, 209211

octal numbers, 179

operators

conditional, 4144

incrementing/decrementing, 177179

order of operation, 177

strict equality/inequality, 240241

order of operation, 177

out-of-scope, 89

P

page load events, 391396

DOMContentLoaded event, 395396

load event, 395396

stages of page loads, 392395

parent objects, 206207, 299300

appending children, 309313

event handling, 409412

properties, 301

removing children, 314315

parentheses (), 2526

parentNode property, 301

parseInt function, 179

parsing JSON data, 259

phases for events, 361364

pizza analogy, 134136

pop method, 149150

position of mouse, 375377

powers (for numbers), 184185

preventDefault function, 366, 374375, 389

previousSibling property, 301

primitives, 138. See also names of specific types

Object-form of, 141, 169173

properties, 196

adding, 197200

in CSS

naming, 291292

setting, 290291

in DOM hierarchy, 298300

child properties, 301302

parent/sibling properties, 301

for Event type, 352

in JSON

names, 252

reading values, 257258

for Keyboard event, 384

for MouseEvent, 375378

browser mouse position, 376377

button clicked, 377378

global mouse position, 375376

removing, 200201

prototype chain, 201204, 207208, 214219

prototypical inheritance model, 212

push method, 147148

Q

querySelector function, 275277

querySelectorAll function, 275277

quotation marks (""), 12, 160161

R

random numbers, 185

raw text, parsing, 259

reading JSON data, 257258

recursively walking DOM hierarchy, 303304

reduce method, 155157

referencing JavaScript files, 111113

RegExp object, 140, 170

remove method, 315

removeChild method, 314315

removeEventListener function, 352353

removing

array values, 149150

class values, 293294

event listeners, 352353

HTML elements, 314315

properties, 200201

requestAnimationFrame function, 8081

return keyword, 3334

returning data

from functions, 33

from nested functions, 9497

rounding numbers, 182

S

scope. See variable scope

screenX property, 375376

screenY property, 375376

script tag, 1011

async attribute, 400

defer attribute, 400401

document structure, 105116

choosing, 114116

JavaScript within HTML document, 109110

JavaScript within JavaScript file, 110113

placement of, 113, 397400

scroll event, 347

semicolon (;), 11

setAttribute method, 286287

setInterval function, 7980

setters, 187193

basic usage, 190191

in classes, 226229

logging example, 191192

uppercase generator example, 191

validation example, 192193

setTimeout function, 78

sharing variables in functions, 98104

shift method, 149150

shiftKey property, 384

shuffling arrays, 213219

sibling objects, 299300

properties, 301

single line comments, 7172

slice method, 164

split method, 165166

splitting strings, 165166

square roots, 184185

starting point, for loops, 61

statements, 11

step region, for loops, 6162

stepping through code, 334336

stopPropagation method, 364366, 412

strict equality/inequality operators, 240241

string literals, 160161

String object, 140, 170173

string type, 137, 170

strings, 12, 159168

case, changing, 168, 191

characters

accessing, 161162

finding, 166167

combining, 163

converting to numbers, 179

in JSON, 253

splitting, 165166

string literals, 160161

substrings, extracting, 164165

style object, 290

styles, 289294. See also CSS

JavaScript and

classList API, 292294

naming CSS properties, 291292

purpose of, 290

setting CSS properties, 290291

rules, 289

substr method, 164165

substrings, extracting, 164165

super keyword, 233

switch statements, 4754

if/else statements, compared, 5154

symbol type, 137

T

text values, changing in DOM, 284285

textContent property, 284285

this keyword, 209211

timers, 7781

requestAnimationFrame function, 8081

setInterval function, 7980

setTimeout function, 78

toggling class values, 294

toLowerCase method, 168

toUpperCase method, 168

trigonometric functions, 183184

type coercion, 240241

typeof keyword, 172, 245

types, 133141. See also names of specific types

list of, 137

objects, 138, 195211

as abstraction, 138139

adding properties, 197200

constructor functions, 171

creating, 197, 205208, 222224

extending, 213220

list of, 140

nesting, 199200

Object type, 196

parent/child objects, 206207

primitives as, 141, 169173

properties, 196

prototype chain, 201204

prototypical inheritance model, 212

removing properties, 200201

this keyword, 209211

pizza analogy, 134136

primitives, 138

Object-form of, 141, 169173

U

UI development with setTimeout function, 78

undefined type, 137, 201, 244246

undefined variables, 9092

unshift method, 147148

uppercase generator example (getters/setters), 191

V

validation example (getters/setters), 192193

values, 15. See also types

in arrays

accessing, 145146

adding, 147148

combining, 155157

counting, 146

filtering, 154155

finding, 150

modifying, 151153

removing, 149150

changing in variables, 1920

in JSON, 253256

arrays, 256

booleans, 254255

null, 256

numbers, 254

objects, 255256

reading, 257258

strings, 253

in log method, 127128

null, 244

undefined, 244246

validating, 192193

var keyword, 90

variable scope, 20, 8392

block scope, 8790

closures, 98104

in console, 339

global scope, 8486

in-scope, 89

local scope, 86

out-of-scope, 89

variables, 1620

changing values, 1920

declaring, 16, 1820, 8687, 90

hoisting, 91

initializing, 16, 1820, 8687

naming, 1718

processing, 9092

sharing in functions, 98104

undefined, 9092

View Source command, DOM view, compared, 326331

W

walking DOM hierarchy, 303304

warn method, 128130

web pages. See document structure

wheel event, 347, 378379

wheelDelta property, 378379

which property, 378

while loops, 66

whitespace in comments, 74

window object, 269, 298

window property, 299

writing

HTML documents, 811

JSON data, 259

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.36.221