JavaScript (Junior Side) Flashcards

1
Q

What is the purpose of variables?

A

they are a way to store information so that we can come back to it later.

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

What is the purpose of a boolean?

A

To make logical decisions.

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

How do youdeclarea variable?

A

by using var, const, or let

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

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

A

By using the assignment operator ( = )

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

What characters are allowed in variable names?

A

letter, number, or dollar sign $

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

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

A

capitalized and lowercase letters, even if they are the same letter, will have two different values if assigned to a variable

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

What is the purpose of a string?

A

For storing a sequence of characters that javScript will not try to interpret / creating “text”

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

What is the purpose of a number?

A

For numbers that may / will be used in mathematical operations

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

How do you update the value of a variable?

A

put the name of the variable with an assignment operator and a new value.

Do not use the “var, let, or const” keywords, because the variable has already been declared.

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

What does the=operator mean in JavaScript?

A

assigns the value of its right operand to its left operand.

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

What is the difference betweennullandundefined?

A

Null is an intentional assignment of no value.

Undefined is an empty value that JS is ‘free to use’

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

For clarity when coming back to reference code at a later time.

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, number, boolean, null, undefined

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

Number

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

What is string concatenation?

A

adding strings together to make a new string

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

Does concat change the original string?

A

No, it makes new strings that consist of the previous strings

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

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

A

math or concatenation

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

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

A

makes a lasting change / adds and assigns

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

What are objects used for?

A

a way to group together sets of data that are related to each other

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

What are object properties?

A

variables inside of an object

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

Describe object literal notation.

A

curly brace, then a property, the a colon, then a comma, then the next property declaration, etc., ended by a closing curly brace

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

How do you remove a property from an object?

A

use the delete operator

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

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

A

dot notation or bracket notation

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

what are arrays used for?

A

for storing a sequence of related information for use at a later time

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

describe array literal notation

A

[ ‘word’, ‘word2’ ]

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

how are arrays different from “plain” objects?

A

arrays are indexed/ have an order, objects are not

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

what is the length property of an array?

A

arrayName.length, a true count of items that are indexed in the array

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

how do we calculate last index of an array?

A

array.length -1

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

What is a function in JavaScript?

A

Functions allow you to package up code for use later in your program.

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

Describe the parts of a function definition.

A

function keyword

optional name

parameters (separated , by , commas)

start of the code block ( { ) with a return…maybe

optional return statement

close of the code block (})

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

Describe the parts of a function call.

A

function name

( ) parenthesis

arguments list

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

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

A

function call just has the name and arguments

function definition has name, parameters, { } , and code block

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

What is the difference between a parameter and an argument?

A

when we define a function, we declare parameters and that when we call a function, we pass it arguments

parameter is placeholder, argument is the actual value

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

Why are function parameters useful?

A

They give us more control over the function

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

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

A
  1. Causes the function to produce a value we can use in our program.
  2. Prevents any more code in the function’s code block from being run.
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

why do we log things to the console?

A

its a debugging tool

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

What is a method?

A

a function stored in the property of an object

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

How is a method different from any other function?

A

Methods must be attached to an object, functions do not

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

How do you remove the last element from an array?

A

.pop( ) method

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

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

A

Math.floor( ) method

floor method of the math object

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

How do you generate a random number?

A

Math.random( )

random method of the math object

0 0.999

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

How do you delete an element from an array?

A

.splice( ) method

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

How do you append an element to an array?

A

.push ( ) method

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

How do you break a string up into an array?

A

.split ( ) method

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

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

A

No!

console.log( ) the string using a method

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

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

A

A LOT

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

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

A

No, example . push( ) or .pop( )

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

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

A

A LOT

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

Give 6 examples of comparison operators.

A

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

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

What data type do comparison expressions evaluate to?

A

booleans

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

What is the purpose of an if statement?

A

to make logical decisions in code

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

Describe the syntax (structure) of an if statement.

A

if keyword, condition, code block

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

What are the three logical operators?

A

&& , ||, !

and, or, not

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

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

A

With a logical operator (either && or ||)

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

what is the purpose of a loop?

A

to repeat functionality when needed

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

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

A

to determine whether or not the loop continues repeating.

if true, loop continues, if false, loop stops.

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

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

A

one full time that the code block has been run.

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

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

A

before the loop code block executes

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

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

A

once before anything happens

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

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

A

before code block of next iteration, and after the final expression

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

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

A

before the condition, and after the code block runs

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

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

What does the ++ increment operator do?

A

adds one to the initialization expression

69
Q

How do you iterate through the keys of an object?

A

with a for…in loop

70
Q

Why do we log things to the console?

A

For debugging purposes

71
Q

What is a “model”?

A

A visual representation of something

72
Q

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

A

the HTML document / the web page itsself

73
Q

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

A

the objects / nodes of the document

74
Q

What is a DOM Tree?

A

the model of a webpage

75
Q

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

A

querySelector(), getElementById()

76
Q

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

A

querySelectorAll(), getElementsByClassName()

77
Q

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

A

so we don’t have to query the DOM again

78
Q

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

A

console.dir( )

dir method of the console object

79
Q

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

A

document needs to be read before JS can interact with it.

80
Q

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

A

Takes the element name, returns the first element that matches

81
Q

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

A

Takes an element name, returns a static (not live) NodeList representing a list of the document’s elements that match the specified group of selectors.

82
Q

Why do we log things to the console?

A

for debugging purposes / so we know whats going on

83
Q

What is the purpose of events and event handling?

A

they allow us to run code when the user interatcs with the page

84
Q

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

A

No

85
Q

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

A

addEventListener()

86
Q

What is a callback function?

A

a function that is passed as an argument to another function, to be called on at a later time during an event.

87
Q

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

A

event object

88
Q

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

the top function will be called by the addEventListener method

the bottom function is being called manually in the method, which will not work

89
Q

What is the className property of element objects?

A

it is a property that gets and sets the value of the class attribute of the specified element.

90
Q

What is the event.target?

A

the element that dispatches the element. the point of interaction on the DOM.

91
Q

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

A

use the className property

92
Q

What is the textContent property of element objects?

A

a property that is used to grab the text content from an element

93
Q

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

A

by using the textContent property

94
Q

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

A

No

95
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

96
Q

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

A

Because they can be accessed at a later time / makes work easier

97
Q

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

A

Focus

98
Q

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

A

Blur

99
Q

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

A

Input

100
Q

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

A

Submit

101
Q

What does the event.preventDefault() method do?

A

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.

102
Q

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

A

It can cause unwanted submissions of forms / actions to occur

103
Q

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

A

The elements() property of the form object

104
Q

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

A

The elements property

105
Q

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

A

You will not catch any errors and waste time

106
Q

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

A

You can see errors as they appear

107
Q

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

A

It creates a new element on the DOM tree

108
Q

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

A

appendChild(pass in Dom element)

109
Q

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

A

attribute name, and values

110
Q

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

A

document.CreatElement()

add child elements to that

put the element to the DOM tree by appending it to a parent element using (appendChild) on the parent object

111
Q

What is the textContent property of an element object for?

A

to create or change text content

112
Q

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

A

className()

setAttribute()

113
Q

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

A
  1. You can repeat functionality quickly.

2. You save time.

114
Q

What is the event.target?

A

the target of the event

115
Q

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

A

because of event delegation / the bubble effect

116
Q

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

A

the tagName property

117
Q

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

A

Takes a CSS selector as its argument, and returns the closest ancestor Element or itself, which matches the selectors. If there are no such element, null.

118
Q

How can you remove an element from the DOM?

A

using the remove() method

119
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 the eventListener to the parent element

120
Q

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

A

the element and its children disappear from the page

121
Q

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

A

takes a selector and returns a boolean value

122
Q

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

A

getAttribute()

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 need to add multiple listener events

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

multiple conditionals would need to be used

125
Q

What does JSON stand for?

A

Java Script Object Notation

126
Q

What are serialization and deserialization?

A

Serializtion converts an object into a byte string, deserialization is when that data gets parsed

127
Q

Why are serialization and deserialization useful?

A

it allows transfer of information across networks

128
Q

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

A

JSON.stringify()

129
Q

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

A

parse()

130
Q

How do you store data in localStorage?

A

setItem()

131
Q

How do you retrieve data from localStorage?

A

getItem()

132
Q

What data type can localStorage save in the browser?

A

JSON Strings

133
Q

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

A

The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point.

134
Q

What is a method?

A

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

the same way you tell the difference between a function definition and a function call

136
Q

Describe method definition syntax (structure).

A

it is the same as a function definition:

function name (){

return
}

137
Q

Describe method call syntax (structure).

A

just like a function call

138
Q

How is a method different from any other function?

A

it must be stored within the property of an object

139
Q

What is the defining characteristic of Object-Oriented Programming?

A
140
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

141
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways

142
Q

What does API stand for?

A

application programming interface

143
Q

What is the purpose of an API?

A

a way for computers to communicate with each other, and for users to interact with simply

144
Q

What is this in JavaScript?

A

an implicit parameter of all JavaScript functions.

145
Q

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

A

a parameter that is available in a function’s code block even though it was never included in the function’s parameter list or declared with var.

146
Q

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

A

at call time

147
Q

What does this refer to in the following code snippet?

var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
A

the character object

148
Q

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

A

you dont know

149
Q

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

A

look to the left of the dot

150
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based

151
Q

What is a prototype in JavaScript?

A

an object that contains properties and (predominantly) methods that can be used by other objects.

152
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

because of the prototype object

153
Q

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

A

within the prototype chain

154
Q

What does the new operator do?

A

it instantiates a new javascript object

155
Q

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

A

the prototype property

156
Q

What does the instanceof operator do?

A

tests whether or not the thing being evaluated was created by the “creator” that we are looking at.

“was ____ created from ____?”

157
Q

what is a client?

A

the person making the request

158
Q

what is a server?

A

a provider of services

159
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET request

160
Q

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

A

http method, request target, request version

161
Q

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

A

protocol version, status code, status text

162
Q

What are HTTP headers?

A

they let let the client and the server pass additional information with an HTTP request or response.

163
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

MDN

164
Q

Is a body required for a valid HTTP request or response message?

A

No

165
Q

What is AJAX?

A

a technique for loading data into part of a page without having to refresh the entire page. The data is often sent in a format called JavaScript Object Notation (or JSON).

166
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

167
Q

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

A

The XMLHttpRequest object

168
Q

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

A

the load event

169
Q

An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

because of prototypical inheritance