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
Q

What does the event.preventDefault() method do?

A

preventing refresh the page

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

What does submitting a form without event.preventDefault() do?

A

It refreshes webpage

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

What property of a form element object contains all of the form’s controls.

A

The HTMLFormElement.elements returns an HTMLFormControlsCollection

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

What is the textContent property of an element object for?

A

textContent property let us add text value to an element object or check text value of an element object

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

Name two ways to set the class attribute of a DOM element.

A

className and setAttribute

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

What are two advantages of defining a function to create something (like the work of creating a DOM tree)?

A

it’s reusable, we can use different data, we can run it whenever we want

31
Q

What is the event.target?

A

target property of the Event interface is a reference to the object onto which the event was dispatched.

32
Q

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

A

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
Q

How can you retrieve the value of an element’s attribute?

A

getAttribute()

34
Q

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?

A

We would have to make a code for individual tabs

35
Q

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?

A

we would have to use conditional statement each time

36
Q

What are serialization and deserialization?

A

taking data and put it into order, deserialization is opposite

37
Q

What is JSON?

A

JSON (JavaScript Object Notation) format for storing and transporting data.

38
Q

Why are serialization and deserialization useful?

A

taking data and organize it into an order, deserialization is opposite

39
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

40
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse

41
Q

How to you store data in localStorage?

A

using localstorage.setItem() method

42
Q

How to you retrieve data from localStorage?

A

using localstorage.getItem() method

43
Q

What data type can localStorage save in the browser?

A

strings

44
Q

When does the ‘beforeunload’ event fire on the window object?

A

before closing application.

45
Q

How can you tell the difference between a method definition and a method call?

A

different syntax calculator.add() vs
add function(x + x) { …}

46
Q

What is the defining characteristic of Object-Oriented Programming?

A

methods are behavior , values are data.
data and methods can be in shared space

47
Q

What are the four “principles” of Object-Oriented Programming?

A

abstraction, encapsulation ,inheritance, polymorphism

48
Q

What is “abstraction”?

A

taking complex functionality and make it accessible

49
Q

What does API stand for?

A

application programing interface

50
Q

What is the purpose of an API?

A

all tools letting programs interact between each other

51
Q

What is this in JavaScript?

A

the this keyword refers to an object. Which object, it depends on how this is being invoked (used or called)

52
Q

What does it mean to say that this is an “implicit parameter”?

A

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
Q

When is the value of this determined in a function; call time or definition time?

A

call time

54
Q

How can you tell what the value of this will be for a particular function or method definition?

A

You can’t , it’s just definition

55
Q

How can you tell what the value of THIS is for a particular function or method call?

A

if there is no function call it’s window. If it’s . its always method of that object

56
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based-inheritance(prototypal)

57
Q

What is a prototype in JavaScript?

A

It’s reusing existing objects that serve as prototype

58
Q

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?

A

their grabbing it from prototype object

59
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

On it’s own prototype.

60
Q

What does the new operator do?

A

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
Q

What property of JavaScript functions can store shared behavior for instances created with keyword new?

A

prototype property

62
Q

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?

A

using setTImeOut()

63
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval()

64
Q

What do setTimeout() and setInterval() return?

A

number id

65
Q

What three things are on the start-line of an HTTP request message?

A

one line, request method, request url and HTTP version

66
Q

What is AJAX?

A

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
Q

What does the AJAX acronym stand for?

A

asynchronous JavaScript and XML

68
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest();

69
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

load event

70
Q

What is Event Bubbling

A

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
Q

What is Event Propagation

A

This is the blanket term for both event bubbling and event capturing

72
Q

What is Event Capturing Phase?

A

?

73
Q

What is Event Delegation

A

It’s event handling pattern. We put single handler on common ancestor and call an event on particular element (event.target)