Browsers and Events - 17% Flashcards

1
Q

addEventListener params

A
  1. Type - ex: ‘click’
  2. Listener - ex: JS Fn or object w/a handleEvent method
  3. Optional 3rd param can be either an options object, or useCapture boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

addEventListener options obj

A

Options obj properties:
- Capture - boolean, see useCapture card
- Once - boolean, Indicates the handler should only be invoked once
- Passive - boolean, The invoked fn will never call preventDefault (even if specified in the fn)
- Signal - This is an AbortSignal - Listener gets removed when the given AbortSignal object’s abort method is called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

addEventListener useCapture boolean

A

Will trigger event handlers on event targets beneath it on the DOM tree
Calls events in order from outside to inside
False by default
Ex: if the inner div is clicked, and the outer div has an event handler, the outer div’s handler function will be called, then the inner div’s handler fn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

History API properties

A
  • length - # of session history entries, includes current page
  • scrollRestoration - Allows web apps to set default scroll restoration behavior on history navigation. Can be auto or manual.
  • state - returns a value representing the state at the top of the history stack - this is a way to look at the state w/o having to wait for a popstate event
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

History API methods

A

back, forward, go, pushState, replaceState
go - Asynchronously loads a page from the session history, -1 for prev page or 1 for the next page. Has no effect if out of bounds. Calling w/o params or a value of 0 reloads the current page.
pushState - pushes the given data onto the session history stack with the specified title (and, if provided, URL) Note: title ignored by all browsers but Safari
replaceState - updates the most recent entry on the history stack to have the specified data, title, and, if provided, URL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

popstate event

A

A popstate event is dispatched to the window each time the active history entry changes while the user navigates the session history. It changes the current history entry to that of the last page the user visited, OR if history.pushState or history.replaceState were used, that history entry is used instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

event objects

A

These are objs automatically passed to event handlers when fired
event.target - this refers to the element that triggered the event (such as a button)
event.currentTarget refers to the element that the eventListener is on
If event listener is on the outer div, and the button was clicked, the event.target is the button and the event.currentTarget is the outer div

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

event bubbling

A

Default behavior of nested elements that have event handlers
Ex: button inside div inside body - if all 3 have event handlers, all 3 will be fired when the button is clicked (starting w/button, then div, then body)
use stopPropogation( ) method on the event object to stop the bubbling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

event capture

A

Reverses the default order of Event Bubbling
ex: normally if button is clicked order is button, div, body - with event capture will be body, then div, then button.
See useCapture boolean card.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Node.js

A

JS runtime - use JS to build network and server-side applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Node.js events

A

Node’s event model is different from JS - relies on listeners to listen for events and emitters to emit events periodically - while this doesn’t sound very different, the code is very different.
Uses on( ) to register an event listener and once( ) to register an event listener that unregisters after running once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

DOM

A

Web API for web documents, represents the document as nodes and objects.
Can be used w/any scripting language (a script is a program run by a browser)
Most nodes are elements, but not all

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

DOM data types (some)

A

Document, node, element, nodeList, attribute, namedNodeMap
Node - every object in the document is a node
Element - objects that implement both the DOM Element interface and the Node interface
NodeList - array of elements
Attribute - nodes in the DOM, much like elements (rare)
NamedNodeMap - like a NodeList, except a Map

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

DOM Interfaces

A

Many DOM objects implement several different interfaces
Ex: HTML form element gets its ‘name’ property from HTMLFormElement interface and its ‘className’ property from HTMLElement interface, but both properties are in the form object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Default actions

A

Actions built into the browser, such as key presses and mouse events. These can be prevented or customized by JS using event.preventDefault method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Pointer events

A

DOM events fired for a pointing device. Designed to create a single DOM event model to handle various pointing input devices (mouse, pen/stylus, touch).

Event types are similar to mouse events (mousedown/pointerdown, mousemove/pointermove, etc.).

The event contains the properties present in mouse events (client coordinates, target element, button states, etc.) in addition to new properties for other forms of input: pressure, contact geometry, tilt, etc.

17
Q

Timers

A

Fns that allow you to delay the execution of code or to repeat code at specified intervals. They are not part of JS, but are provided by the browser or runtime environment.

The 2 main timer fns are setTimeout and setInterval.

Both return an ID which can be used to stop the timer with clearTimeout() or clearInterval()

18
Q

Debouncing

A

Used to limit the time b/t mult executions of a fn. The idea is to group sequential calls in a single one, so you don’t overload the browser.
ex:
window.addEventListener(‘resize’,
debounce(() => console.log(‘resized’), 300);
- Fn will be triggered once the user stops resizing

19
Q

Phases of Event Propogation

A

Capturing - event goes through the ancestor elements down to the target element
Target - reaches the target
Bubbling - bubbling begins

20
Q

table methods
table.createTbody
tbody.insertRow

A
21
Q

cookie

A

add a single cookie to a webpage with document.cookie = “key=value”

22
Q

Ensure cache is not used

A

W/dev tools opened, long-press the reload button and select ‘Hard reload’
Access the Network panel, check the ‘disable cache’ checkbox

23
Q

Format code in Sources panel

A

Click the ‘pretty print’ icon at the bottom of the editor pane

24
Q

localStorage

A

When storing an obj, it gets stringified, so must use JSON.parse to turn it back into an obj upon retrieval.

25
Q

document.body

A

.insertBefore (no insert after)
If you need to insert after, will need to use .nextSibling w/the 2nd arg
ex:
document.body.insertBefore(el1, el2.nextSibling)
^ this acheives adding el1 after el2

26
Q
A