JavaScript Flashcards

(43 cards)

1
Q
  • What is a function in JavaScript?
A

a set of statements that performs a task or calculates a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • Describe the parts of a functiondefinition.
A

Function keyword
the first line (including the argument declarations), and the so-called body of the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  • Describe the parts of a functioncall.
A

the name of the function being executed followed by a list of values, called arguments, which are assigned to the parameters in the function definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  • When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
A

The definition has a code block while the call doesn’t
Parameter are a new thing while the call is just inserting something

Function keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • What is the difference between aparameterand anargument?
A

Parameter are place holder names for when something is defined

Arguments are used when it is called .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • How do you compare two different expressions in the same condition?
A

Using one of the logical operators &&, ||

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

What is the event.target?

A

It is a reference to the object onto which the event was dispatched
Its the element that the event originated

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

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

A

Bubbling

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

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

A

Element tag name; property comes back upperCased

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

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

A

It takes a valid css selector to match the element and it returns the closest ancestor element or itself; closest searches outwards while query is inward.

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

How can you remove an element from the DOM?

A

Using the remove method; element.remove()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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 an event listener to its ancestor; event delegation

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

What is the affect of setting an element to display: none?

A

It hides its content, does not take any space, outside of the flow.

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

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

A

It takes a valid css selector and returns true if the element matches the selectors otherwise false

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

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

A

getAttribute; the value of the attribute we’re trying to get

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

At what steps of the solution would it be helpful to log things to the console?

A

After every line of code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
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

You would need a separate function for each view

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

Does the document.createElement() method insert a new element into the page?

19
Q

How do you add an element as a child to another element?

A

appendChild; parent.appendChild(child)

20
Q

What do you pass as the arguments to the element.setAttribute() method?

A

Its new attribute and the new value

21
Q

What steps do you need to take in order to insert a new element into the page?

A

First is to create a node(element) and then where you want to place it .

22
Q

What is the textContent property of an element object for?

A

To change or add text or view current text.

23
Q

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

A

setAttribute and className

24
Q

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

A

You can reuse it

25
What event is fired when a user places their cursor in a form control?
focus
26
What event is fired when a user's cursor leaves a form control?
blur
27
What event is fired as a user changes the value of a form control?
input
28
What event is fired when a user clicks the "submit" button within a
?
Submit; it fires on the form event not the submit button
29
What does the event.preventDefault() method do?
tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be
30
What does submitting a form without event.preventDefault() do?
Your page reloads
31
What property of a form element object contains all of the form's controls.
Form.elements; the elements property
32
What property of a form control object gets and sets its value?
The value property
33
What is one risk of writing a lot of code without checking to see if it works so far?
Chaos; you won't know what code will work and what won't.
34
What is an advantage of having your console open when writing a JavaScript program?
To see if there's any errors
35
Why is storing information about a program in variables better than only storing it in the DOM?
You're able to call it back at any time.
36
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
complicated , we wouldn't be able to keep track. Ease of access.
37
How do you update the text within an element using JavaScript?
Use the textContent property to change the text of an element
38
What is the textContent property of element objects?
sets or returns the text content of the specified node, and all its descendants.
39
How do you update the CSS class attribute of an element using JavaScript?
Using className
40
What is the className property of element objects?
gets and sets the value of the class attribute of the specified element.; not a css selector
41
DOM EVENTS
42
Why do we log things to the console?
To verify data
43
What is the purpose of events and event handling?
This is a block of code (usually a JavaScript function that you as a programmer create) that runs when the event fires.register different event handlers on elements in an HTML document