javascript Flashcards

(146 cards)

1
Q

What is the purpose of variables?

A

used to store information to be referenced and manipulated

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

How do you declare a variable?

A

by using the var keyward

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

How do you initialize (assign a value to) a variable?

A

by adding an equal sign to the right of the variable name

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

What characters are allowed in variable names?

A

The period, the underscore, and the characters $, #, and @

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

What does it mean to say that variable names are “case sensitive”?

A

it means that names need to be identical

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

What is the purpose of a string?

A

used for data values that are made up of ordered sequences of characters

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

What is the purpose of a number?

A

to give a number value to a variable

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

What is the purpose of a boolean?

A

to assign true or false to a variable

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

What does the = operator mean in JavaScript?

A

to assign

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

How do you update the value of a variable?

A

by reassigning it

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

What is the difference between null and undefined?

A

null is set but undefined is a return value set by javaScript

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

to identify which console log belongs to which.

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

Give five examples of JavaScript primitives.

A

string, null, numbers , undefined boolean

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

What data type is returned by an arithmetic operation?

A

numbers

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

What is string concatenation?

A

adding 2 strings together

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

What purpose(s) does the + plus operator serve in JavaScript?

A

addition

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

What data type is returned by comparing two values (, ===, etc)?

A

boolean

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

What does the += “plus-equals” operator do?

A

adds and assign

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

What are objects used for?

A

Objects group together a set of variables and functions

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

What are object properties?

A

a simple association between name and value

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

Describe object literal notation.

A

an array of key:value pairs

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

How do you remove a property from an object?

A

by using the delete operator

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

What are the two ways to get or update the value of a property?

A

by dot notation and bracket notation

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

What are arrays used for?

A

to store more then one information at a time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
where you define a new array using just empty brackets
26
How are arrays different from "plain" objects?
Objects represent properties while arrays create and store list of data in a single variable
27
What number represents the first index of an array?
0
28
What is the length property of an array?
.length
29
How do you calculate the last index of an array?
length - 1
30
What is a function in JavaScript?
a set of statements that performs a task or calculates a value
31
Describe the parts of a function definition.
a set of inputs, a set of outputs, and a rule that relates the elements of the set of inputs to the elements
32
Why are function parameters useful?
because they allow storing data that the function needs to work with
33
What two effects does a return statement have on the behavior of a function?
the return statement returns the values inside the function then anything after the return statement will not run.
34
Describe the parts of a function call.
arguments: an array-like object containing the argument passed to the currently executing function callee: the currently executing function. caller: the function that invoked the currently executing function. length: the number of arguments passed to the function
35
When comparing them side-by-side, what are the differences between a function call and a function definition?
a function call is invoking or calling that function a function definition is defining the function
36
What is the difference between a parameter and an argument?
function parameters are names listed in the function's definition. arguments are the real values passed to the function.
37
Why do we log things to the console?
to see the code output
38
What is a method?
a method is a function which is a property of an object.
39
How is a method different from any other function?
method is associated with an object
40
How do you remove the last element from an array?
by using the pop() method
41
How do you round a number down to the nearest integer?
by using the method Math.floor()
42
How do you generate a random number?
by using the math.random method
43
How do you delete an element from an array?
by using the splice() method
44
How do you append an element to an array?
by using the push or the unshift method
45
How do you break a string up into an array?
by using the split method
46
Do string methods change the original string? How would you check if you weren't sure?
they don't modify the original string. the way to check it is by using console.log
47
Roughly how many string methods are there according to the MDN Web docs?
around 50
48
Is the return value of a function or method useful in every situation?
yes
49
Roughly how many array methods are there according to the MDN Web docs?
around 50
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
51
Give 6 examples of comparison operators.
===, !== , < , >, <=, >=
52
What data type do comparison expressions evaluate to?
boolean
53
What is the purpose of an if statement?
decision-making statement that guides a program to make decisions based on specified criteria
54
Is else required in order to use an if statement?
no
55
Describe the syntax (structure) of an if statement.
if keyward, conditoin, then the code to run if value is true
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
by using a logical operator
58
What is the purpose of a loop?
to repeats a sequence of instructions until a specific condition is met
59
What is the purpose of a condition expression in a loop?
to repeat the code until the condition is met
60
What does "iteration" mean in the context of loops?
Means how many times the loop will loop.
61
When does the condition expression of a while loop get evaluated?
Before each iteration.
62
When does the initialization expression of a for loop get evaluated?
Once before the loop begins.
63
When does the condition expression of a for loop get evaluated?
Before each loop iteration.
64
When does the final expression of a for loop get evaluated?
At the end of every loop iteration.
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
66
What does the ++ increment operator do?
Adds one to the operand.
67
How do you iterate through the keys of an object?
Using the for in statement.
68
Why do we log things to the console?
to see what the code is and what it does
69
Which "document" is being referred to in the phrase Document Object Model?
the HTML document
70
What is the word "object" referring to in the phrase Document Object Model?
the document is an object
71
Give two examples of document methods that retrieve a single element from the DOM.
document. querySelector | document. getElementByTagName()
72
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.querySelectorAll
73
Why might you want to assign the return value of a DOM query to a variable?
so we can select the value of the variable and manipulate it
74
What console method allows you to inspect the properties of a DOM element object?
console.dir
75
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
so that the document load first then lastly the script
76
What does document.querySelector() take as its argument and what does it return?
it takes all css selectors, tags, and it returns the selected element as a value.
77
What does document.querySelectorAll() take as its argument and what does it return?
it takes all css selectors, tags, and it returns All selected elements as a value.
78
What is a "model"?
a representation of something
79
What is a DOM Tree?
a collection tree that represents the dom
80
Why do we log things to the console?
to see the output of the code
81
What is the purpose of events and event handling?
used to handle and verify user input, user actions, and browser actions
82
Are all possible parameters required to use a JavaScript method or function?
no
83
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener
84
What is a callback function?
a call-back function is a function passed into another function as an argument.
85
What object is passed into an event listener callback when the event fires?
a function
86
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
event.target is a reference to the object onto which the event was dispatched. console log the event.target to make sure what the value is. to learn more information about it we check the MDN documents
87
What is the difference between these two snippets of code?
the first one doesnt have a callback function the second one has a function as its second argument
88
What is the className property of element objects?
the class name property is used to manipulate the class that's giving to an element
89
How do you update the CSS class attribute of an element using JavaScript?
by querySelecting the element then using the className property to give that element a different className
90
What is the textContent property of element objects?
the textContent property help us manipulate the text content within the element that holds the text
91
How do you update the text within an element using JavaScript?
by using the textContent property
92
Is the event parameter of an event listener callback always useful?
yes
93
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
more complicated
94
Why is storing information about a program in variables better than only storing it in the DOM?
because its easier to access
95
What event is fired when a user places their cursor in a form control?
focus
96
What event is fired when a user's cursor leaves a form control?
blur
97
What event is fired as a user changes the value of a form control?
input
98
What event is fired when a user clicks the "submit" button within a ?
the form submits
99
What does the event.preventDefault() method do?
it prevents the default behavior of the form
100
What does submitting a form without event.preventDefault() do?
it refreshes the page or sends the user to a different page
101
What property of a form element object contains all of the form's controls.
elements
102
What property of a form control object gets and sets its value?
.value
103
What is one risk of writing a lot of code without checking to see if it works so far?
not console logging it
104
What is an advantage of having your console open when writing a JavaScript program?
to see what the code is doing
105
Does the document.createElement() method insert a new element into the page?
yes
106
How do you add an element as a child to another element?
by using the appendChild method
107
What do you pass as the arguments to the element.setAttribute() method?
you give it 2 arguments first is the attribute second is the value
108
What steps do you need to take in order to insert a new element into the page?
createElement then return that element
109
What is the textContent property of an element object for?
to set the text of an element
110
Name two ways to set the class attribute of a DOM element.
set attribute or by using className
111
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
we are able to reuse that function and call it at anytime anywhere
112
What is the event.target?
a reference to the object onto which the event was dispatched
113
Why is it possible to listen for events on one element that actually happen its descendent elements?
because of event bubbling
114
What DOM element property tells you what type of element it is?
tagName
115
How can you remove an element from the DOM?
by using the element.remove method
116
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?
by adding the function to the parent element and then using event bubbling
117
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?
by adding the function to the parent element and then using event bubbling
118
What is the event.target?
a reference to the object onto which the event was dispatched
119
What is the affect of setting an element to display: none?
it hides that element display from the webpage
120
What does the element.matches() method take as an argument and what does it return?
it takes a css selector as a string and returns the match as a value
121
How can you retrieve the value of an element's attribute?
by using getAttribute
122
At what steps of the solution would it be helpful to log things to the console?
at every step
123
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?
you would have multiple eventlisteners that listen to multiple clicks
124
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?
very long with multiple lines of code and multiple conditions that check
125
What is JSON?
is a text-based data format following JavaScript object syntax
126
What are serialization and deserialization?
Serialization is the process of turning an object in memory into a stream of bytes. Deserialization is the reverse process: turning a stream of bytes into an object in memory.
127
Why are serialization and deserialization useful?
because you can turn objects to bytes and transmit them
128
How do you serialize a data structure into a JSON string using JavaScript?
by using the json.stringfy
129
How do you deserialize a JSON string into a data structure using JavaScript?
by using json.parse
130
How to you store data in localStorage?
by using the set item method
131
How to you retrieve data from localStorage?
by using the get item method
132
What data type can localStorage save in the browser?
object
133
When does the 'beforeunload' event fire on the window object?
before the document loads
134
What is a method?
is a function which is a property of an object
135
How can you tell the difference between a method definition and a method call?
by the syntax of it
136
Describe method definition syntax (structure).
``` we first create an object inside the object we create a function that does something then return the function const obj = { function() { return 'hi' } }; ```
137
Describe method call syntax (structure).
object.method name
138
How is a method different from any other function?
A method consists of a code that can be called by the name of its object and its method name using dot notation or square bracket notation
139
What is the defining characteristic of Object-Oriented Programming?
encapsulation, inheritance and polymorphism
140
What are the four "principles" of Object-Oriented Programming?
Abstraction Encapsulation Inheritance Polymorphism
141
What is "abstraction"?
The process of removing physical, spatial, or temporal details
142
What does API stand for?
application programming interface
143
What is the purpose of an API?
allows applications to access data and interact with external software components
144
What does the new operator do?
lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
145
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
146
What does the instanceof operator do?
checks if an object is giving a type