javascript Flashcards

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
Q

Describe array literal notation.

A

where you define a new array using just empty brackets

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

How are arrays different from “plain” objects?

A

Objects represent properties while arrays create and store list of data in a single variable

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

What number represents the first index of an array?

A

0

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

What is the length property of an array?

A

.length

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

How do you calculate the last index of an array?

A

length - 1

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

Describe the parts of a function definition.

A

a set of inputs, a set of outputs, and a rule that relates the elements of the set of inputs to the elements

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

Why are function parameters useful?

A

because they allow storing data that the function needs to work with

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

What two effects does a return statement have on the behavior of a function?

A

the return statement returns the values inside the function then anything after the return statement will not run.

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

Describe the parts of a function call.

A

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

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

a function call is invoking or calling that function a function definition is defining the function

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

What is the difference between a parameter and an argument?

A

function parameters are names listed in the function’s definition. arguments are the real values passed to the function.

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

Why do we log things to the console?

A

to see the code output

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

What is a method?

A

a method is a function which is a property of an object.

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

How is a method different from any other function?

A

method is associated with an object

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

How do you remove the last element from an array?

A

by using the pop() method

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

How do you round a number down to the nearest integer?

A

by using the method Math.floor()

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

How do you generate a random number?

A

by using the math.random method

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

How do you delete an element from an array?

A

by using the splice() method

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

How do you append an element to an array?

A

by using the push or the unshift method

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

How do you break a string up into an array?

A

by using the split method

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

Do string methods change the original string? How would you check if you weren’t sure?

A

they don’t modify the original string. the way to check it is by using console.log

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

Roughly how many string methods are there according to the MDN Web docs?

A

around 50

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

Is the return value of a function or method useful in every situation?

A

yes

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

Roughly how many array methods are there according to the MDN Web docs?

A

around 50

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

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

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

Give 6 examples of comparison operators.

A

===, !== , < , >, <=, >=

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

What data type do comparison expressions evaluate to?

A

boolean

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

What is the purpose of an if statement?

A

decision-making statement that guides a program to make decisions based on specified criteria

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

Is else required in order to use an if statement?

A

no

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

Describe the syntax (structure) of an if statement.

A

if keyward, conditoin, then the code to run if value is true

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

What are the three logical operators?

A

&&, ||, !

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

How do you compare two different expressions in the same condition?

A

by using a logical operator

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

What is the purpose of a loop?

A

to repeats a sequence of instructions until a specific condition is met

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

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

A

to repeat the code until the condition is met

60
Q

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

A

Means how many times the loop will loop.

61
Q

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

A

Before each iteration.

62
Q

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

A

Once before the loop begins.

63
Q

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

A

Before each loop iteration.

64
Q

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

A

At the end of every loop iteration.

65
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

66
Q

What does the ++ increment operator do?

A

Adds one to the operand.

67
Q

How do you iterate through the keys of an object?

A

Using the for in statement.

68
Q

Why do we log things to the console?

A

to see what the code is and what it does

69
Q

Which “document” is being referred to in the phrase Document Object Model?

A

the HTML document

70
Q

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

A

the document is an object

71
Q

Give two examples of document methods that retrieve a single element from the DOM.

A

document. querySelector

document. getElementByTagName()

72
Q

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

A

document.querySelectorAll

73
Q

Why might you want to assign the return value of a DOM query to a variable?

A

so we can select the value of the variable and manipulate it

74
Q

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

A

console.dir

75
Q

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

so that the document load first then lastly the script

76
Q

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

A

it takes all css selectors, tags, and it returns the selected element as a value.

77
Q

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

A

it takes all css selectors, tags, and it returns All selected elements as a value.

78
Q

What is a “model”?

A

a representation of something

79
Q

What is a DOM Tree?

A

a collection tree that represents the dom

80
Q

Why do we log things to the console?

A

to see the output of the code

81
Q

What is the purpose of events and event handling?

A

used to handle and verify user input, user actions, and browser actions

82
Q

Are all possible parameters required to use a JavaScript method or function?

A

no

83
Q

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

A

addEventListener

84
Q

What is a callback function?

A

a call-back function is a function passed into another function as an argument.

85
Q

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

A

a function

86
Q

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

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
Q

What is the difference between these two snippets of code?

A

the first one doesnt have a callback function the second one has a function as its second argument

88
Q

What is the className property of element objects?

A

the class name property is used to manipulate the class that’s giving to an element

89
Q

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

A

by querySelecting the element then using the className property to give that element a different className

90
Q

What is the textContent property of element objects?

A

the textContent property help us manipulate the text content within the element that holds the text

91
Q

How do you update the text within an element using JavaScript?

A

by using the textContent property

92
Q

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

A

yes

93
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

more complicated

94
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

because its easier to access

95
Q

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

A

focus

96
Q

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

A

blur

97
Q

What event is fired as a user changes the value of a form control?

A

input

98
Q

What event is fired when a user clicks the “submit” button within a ?

A

the form submits

99
Q

What does the event.preventDefault() method do?

A

it prevents the default behavior of the form

100
Q

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

A

it refreshes the page or sends the user to a different page

101
Q

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

A

elements

102
Q

What property of a form control object gets and sets its value?

A

.value

103
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

not console logging it

104
Q

What is an advantage of having your console open when writing a JavaScript program?

A

to see what the code is doing

105
Q

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

A

yes

106
Q

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

A

by using the appendChild method

107
Q

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

A

you give it 2 arguments first is the attribute second is the value

108
Q

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

A

createElement then return that element

109
Q

What is the textContent property of an element object for?

A

to set the text of an element

110
Q

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

A

set attribute or by using className

111
Q

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

A

we are able to reuse that function and call it at anytime anywhere

112
Q

What is the event.target?

A

a reference to the object onto which the event was dispatched

113
Q

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

A

because of event bubbling

114
Q

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

A

tagName

115
Q

How can you remove an element from the DOM?

A

by using the element.remove method

116
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

by adding the function to the parent element and then using event bubbling

117
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

by adding the function to the parent element and then using event bubbling

118
Q

What is the event.target?

A

a reference to the object onto which the event was dispatched

119
Q

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

A

it hides that element display from the webpage

120
Q

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

A

it takes a css selector as a string and returns the match as a value

121
Q

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

A

by using getAttribute

122
Q

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

A

at every step

123
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 have multiple eventlisteners that listen to multiple clicks

124
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

very long with multiple lines of code and multiple conditions that check

125
Q

What is JSON?

A

is a text-based data format following JavaScript object syntax

126
Q

What are serialization and deserialization?

A

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
Q

Why are serialization and deserialization useful?

A

because you can turn objects to bytes and transmit them

128
Q

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

A

by using the json.stringfy

129
Q

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

A

by using json.parse

130
Q

How to you store data in localStorage?

A

by using the set item method

131
Q

How to you retrieve data from localStorage?

A

by using the get item method

132
Q

What data type can localStorage save in the browser?

A

object

133
Q

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

A

before the document loads

134
Q

What is a method?

A

is a function which is a property of an object

135
Q

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

A

by the syntax of it

136
Q

Describe method definition syntax (structure).

A
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
Q

Describe method call syntax (structure).

A

object.method name

138
Q

How is a method different from any other function?

A

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
Q

What is the defining characteristic of Object-Oriented Programming?

A

encapsulation, inheritance and polymorphism

140
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

141
Q

What is “abstraction”?

A

The process of removing physical, spatial, or temporal details

142
Q

What does API stand for?

A

application programming interface

143
Q

What is the purpose of an API?

A

allows applications to access data and interact with external software components

144
Q

What does the new operator do?

A

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
Q

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

A

prototype

146
Q

What does the instanceof operator do?

A

checks if an object is giving a type