JavaScript Flashcards

1
Q

What is the purpose of a loop?

A

To execute a block of code as long as specified condition is true

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

What is the purpose of a condition expression in a loop?

A

The purpose of condition expression in a loop is to be tested each time loop runs. As long as condition is true loop keeps running

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

What does “iteration” mean in the context of loops?

A

repetition of a process

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

When does the initialization expression of a for loop get evaluated?

A

only first time before loop starts

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

When does the condition expression of a for loop get evaluated?

A

before each loop iteration

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

When does the final expression of a for loop get evaluated?

A

At the end of each loop iteration

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

What is the word “object” refers to in the phrase Document Object Model?

A

The word “object” refers to the structured representation of an HTML or XML document.

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

What is a DOM Tree?

A

A collection of objects in the computer memory that represent the HTML elements that define a web page.

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

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

document.querySelectorAll()

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

What console method allows you to inspect the properties of a DOM element object?

A

console.dir()

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

What does document.querySelector() take as its argument and what does it return?

A

document.querySelector() takes a CSS selector string as its argument. And returns the first element that matches specified CSS selector.

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

What does document.querySelectorAll() take as its argument and what does it return?

A

It takes CSS string selectors as argument and returns static NodeList representing a list of documents that match argument

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

What is the purpose of events and event handling?

A

It’s to interact with users in a specific way depends on user actions

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

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

addEventListener

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

What object is passed into an event listener callback when the event fires?

A

function object

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

How do you update the CSS class attribute of an element using JavaScript?

A

by calling className property

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

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

due to the event bubbling

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

What DOM element property tells you what type of element it is?

A

tagName

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

What does the element.closest() method take as its argument and what does it return?

A

As argument it takes string as CSS selector, it’s heading towards document root until it finds a node that matches provided selector string

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

How can you remove an element from the DOM?

A

By using remove() method -> element.remove()

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

If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

add eventListener to the parent element and verify from which element event come from (condition)

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

Is the event parameter of an event listener callback always useful?

A

yes

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

What event is fired when a user places their cursor in a form control?

A

focus

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

What event is fired when a user’s cursor leaves a form control?

A

blur

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does the event.preventDefault() method do?
preventing refresh the page
26
What does submitting a form without event.preventDefault() do?
It refreshes webpage
27
What property of a form element object contains all of the form's controls.
The HTMLFormElement.elements returns an HTMLFormControlsCollection
28
What is the textContent property of an element object for?
textContent property let us add text value to an element object or check text value of an element object
29
Name two ways to set the class attribute of a DOM element.
className and setAttribute
30
What are two advantages of defining a function to create something (like the work of creating a DOM tree)?
it's reusable, we can use different data, we can run it whenever we want
31
What is the event.target?
target property of the Event interface is a reference to the object onto which the event was dispatched.
32
What does the element.matches() method take as an argument and what does it return?
takes string as an argument. Checks if the element would be selected by specified CSS selector. Returns true or false const birds = document.querySelectorAll('LI') for (const bird of birds) { if (bird.matches('.endangered')) { console.log('whee') } }
33
How can you retrieve the value of an element's attribute?
getAttribute()
34
If you were to add another tab and view to your HTML, but you didn't use event delegation, how would your JavaScript code be written instead?
We would have to make a code for individual tabs
35
If you didn't use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
we would have to use conditional statement each time
36
What are serialization and deserialization?
taking data and put it into order, deserialization is opposite
37
What is JSON?
JSON (JavaScript Object Notation) format for storing and transporting data.
38
Why are serialization and deserialization useful?
taking data and organize it into an order, deserialization is opposite
39
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
40
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
41
How to you store data in localStorage?
using localstorage.setItem() method
42
How to you retrieve data from localStorage?
using localstorage.getItem() method
43
What data type can localStorage save in the browser?
strings
44
When does the 'beforeunload' event fire on the window object?
before closing application.
45
How can you tell the difference between a method definition and a method call?
different syntax calculator.add() vs add function(x + x) { ...}
46
What is the defining characteristic of Object-Oriented Programming?
methods are behavior , values are data. data and methods can be in shared space
47
What are the four "principles" of Object-Oriented Programming?
abstraction, encapsulation ,inheritance, polymorphism
48
What is "abstraction"?
taking complex functionality and make it accessible
49
What does API stand for?
application programing interface
50
What is the purpose of an API?
all tools letting programs interact between each other
51
What is this in JavaScript?
the this keyword refers to an object. Which object, it depends on how this is being invoked (used or called)
52
What does it mean to say that this is an "implicit parameter"?
meaning that it is available in a function's code block even though it was never included in the function's parameter list or declared with var
53
When is the value of this determined in a function; call time or definition time?
call time
54
How can you tell what the value of this will be for a particular function or method definition?
You can't , it's just definition
55
How can you tell what the value of THIS is for a particular function or method call?
if there is no function call it's window. If it's . its always method of that object
56
What kind of inheritance does the JavaScript programming language use?
prototype-based-inheritance(prototypal)
57
What is a prototype in JavaScript?
It's reusing existing objects that serve as prototype
58
How is it possible to call methods on strings, arrays, and numbers even though those methods don't actually exist on objects, arrays, and numbers?
their grabbing it from prototype object
59
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
On it's own prototype.
60
What does the new operator do?
let you create object for a function ,new create plain js object, add property to the new object, binds new object instance as this ,return this if function doesn't return any object.
61
What property of JavaScript functions can store shared behavior for instances created with keyword new?
prototype property
62
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
using setTImeOut()
63
How can you set up a function to be called repeatedly without using a loop?
setInterval()
64
What do setTimeout() and setInterval() return?
number id
65
What three things are on the start-line of an HTTP request message?
one line, request method, request url and HTTP version
66
What is AJAX?
Programing concept, build in HTML XMLHTTPRequest object is used to execute Ajax on webpages, allowing websites to load content onto the screen without refreshing the page
67
What does the AJAX acronym stand for?
asynchronous JavaScript and XML
68
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest();
69
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load event
70
What is Event Bubbling
Event bubbling is the order in which event handlers are called when one element is nested inside a second element, and both elements have registered a listener for the same event (a click, for example).
71
What is Event Propagation
This is the blanket term for both event bubbling and event capturing
72
What is Event Capturing Phase?
?
73
What is Event Delegation
It's event handling pattern. We put single handler on common ancestor and call an event on particular element (event.target)