Objects, Functions, and Classes Flashcards

1
Q

two types of exports

A

named

default

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

considerations for using JS modules

A

the value of an imported feature is read only; it cannot be modified, but its properties can be changed (like const)

features are imported as live bindings. if the value of an imported feature changes in the source module, it is updated in the target module

when importing a feature from a module, a single dot (.) means the current directory, and two dots (..) means the parent directory

module imports are moved or hoisted to the beginning of the current scope; this means that a module can be imported anywhere in the module

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

decorator

A

wrapper function that can be used to extend the behavior of another function. it receives the original function as a parameter and returns a new function with the extended behavior.

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

in order to decorate a class or class method, it must be prefixed with…

A

@nameOfDecorator

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

when a class method is decorated, the decorator receives three parameters…

A

target, name, and descriptor

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

when a class is decorated, the decorator only receives…

A

the target parameter

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

property descriptor of an object’s property

A

can be used in a decorator to modify its attributes; for instance, the writable attribute can be set to false to make a class read only

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

using property descriptor

A

each object property has a property descriptor
method to return a property descriptor:
Object.getOwnPropertyDescriptor();

value: refers to the value of the property
writable: is true if the value of the property may be changed
configurable: true if the property descriptors of the property can be changed
enumerable: attribute is true if the property is appears during the enumeration of the object’s properties

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

scope

A

which variables can be accessed

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

hoisting

A

when a variable or function is moved to the top of their scope

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

asynchronous

A

non blocking code

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

some standard events

A
click
change
focus
input
keydown
keyup
load
mousedown
mouseup
resize
scroll
submit
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

in order to use custom event…

A

you have to dispatch it

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

two ways to handle events

A

addEventListener() - method of the EventTarget object that allows setting up a function that is called whenever the specified event is delivered to the target

onevent handler - property of an element (for example ‘onclick’) can be assigned to a single event handler function that is called when the event occurs

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

considerations for using addEventListener()

A

it’s the more common method, lots of flexibility

target: any object that supports events, but common targets are Element, Document, and Window
parameters: the method can also accept an options object and useCapture (true or false) as parameters. the options objects represents the characteristics of the event listener
benefits: method allows adding more than a single handler for a particular event. it also allows controlling the phase (bubbling or capturing) when the listener is activated)

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

commonly used DOM event properties

A

target: refers to an element that triggered an event
currentTarget: refers to an element where the event listener is attached
clientX: horizontal coordinate of mouse click
clientY: vertical coordinate of mouse click

17
Q

how to remove event listener

A

removeEventListener

18
Q

considerations for registering on even handlers

A

programmatic triggers: an even handler can be called programmatically. if ‘button’ is an element that represents a button, button.onclick() can be called

non element objects: non element objects like window, document, and XMLHttpRequest also support the use of onevent handlers

this keyword: when the handler is invoked, the this keyword is set to the DOM element on which the handler is registered

19
Q

event propagation

A

capturing: browser checks for an event handler for the fired event on the outermost ancestor and runs it. moving from top to bottom the same is done for each next element until the browser reachers the target element.
bubbling: the browser checks for an event handler for the fired event on the target element and runs it. moving from bottom to top, the same is done for each immediate ancestor element until the browser reaches

20
Q

6 fundamental DOM data types

A
Document
Node
Element
NodeList
Attribute
NamedNodeMap
21
Q

some methods to retrieve elements from the DOM

A

getElementById()
querySelector()
querySelectorAll()

22
Q

some methods to manipulate the DOM

A

appendChild()
setAttribute()

some properties:
innerHTML
style

23
Q

window

A

this object represents the browser window containing a DOM document and exposes several properties and methods

location: location.href - returns the URL of the current window / assigning a string URL to this property redirects the browser to the URL
history: contains the browser session history which contains methods for moving forward and backward etc

open() - this method can be used to open a link in a current or new window/tab

scrollTo() used to scroll to a specific location in the document by providing x and y coordinates

24
Q

css selectors

A

elements: string (e.g. ‘h3’)
id: pound (e.g. #subheader)
class: period (e.g. .bold)

25
Q

to retrieve elements by class or tag

A
getElementsByClassName() (string of class name)
getElementsByTagName()
26
Q

panels for chrome devtools

A

elements: used to inspect and modify the DOM and CSS
console: used to execute JS code and view logged messages
sources: three parts –> file navigator, code editor, JS debugging
scope pane: in the JS debugging pane can be used to check the values of variables
watch pane: monitor values over time

network: used to check the network activity of a web page; allows for inspecting whether resources are actually being downloaded or uploaded; used to inspect the properties of each resource

27
Q

network panel

A

resources
properties
network log

28
Q

main API

A
DOM API
Fetch API
History API
Geolocation API
Canvas API
URL API
Web Storage API