Javascript Flashcards

1
Q

What is the purpose of variables?

A

used to store information to be referenced and manipulated in a computer program

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

How do you declare a variable?

A

with a var, let or const

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

using the assignment operator

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

letters, numbers, dollar signs, nonpunctuation characters

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

takes account lower or uppercase

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

holds text characters, literal constant

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

stores numbers…

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

determines true or false

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

assignment operator

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

reassignment

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 means no value, undefined means just not defined at all

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

gives a good point of reference

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

operation of joining character strings end-to-end

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 and string concatenation

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 the value on the right, to the variable on the left, and then assigns that value back into the variable on the left

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

What are objects used for?

A

stores its state in fields

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

What are object properties?

A

Object properties are defined as 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, with a colon separating the keys and values, and a comma after every key:value pair, except for the last

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

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

dot or bracket notation
object.property
object[‘property’]

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

What are arrays used for?

A

ordered lists

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

Describe array literal notation.

A

square brackets [ ] with a comma between each item

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

arrays are ordered, items are indexed, arrays will repair themselves if items are deleted, arrays have a set length

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

count and stores the number of items in the array

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 repeatable series of statements to accomplish an operation

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

function keyword
function name
parameters
code block

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

Describe the parts of a function call.

A

name of function, (), arguments

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

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

A

function call is shorter since it doesn’t have to define the function in curly braces

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

What is the difference between a parameter and an argument?

A

para: placeholders, arguments are real data

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

Why are function parameters useful?

A

dont need to use a var, great placeholder

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

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

A

allows users to assign the result of the function and closes 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 keep track of our progress and to verify our output

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

What is a method?

A

function that 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

methods are called with dot notation since they’re a property

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

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

floor method of math object

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

random method of math object

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

pop to remove at end, splice to remove at a point, shift to remove begining

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

push 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

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

strings are immutable, can check through console.log

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

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

A

no sometimes it’s built in

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

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

A

36

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

Give 6 examples of comparison operators.

A

> , < , >= , <= , === , and !== .

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

Describe the syntax (structure) of an if statement.

A

if (condition) inside code-block

statement1

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

What are the three logical operators?

A

|| (OR), && (AND), ! (NOT).

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

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

A

logical and or logical or

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

What is the purpose of a loop?

A

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

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

A

Condition is an expression that is tested each time the loop repeats. As long as condition is true, the loop keeps running.

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

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

A

Iteration is the repetition of a function or process in a computer program.

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

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

A

Before the code-block executes

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

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

A

The very first action, before anything

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

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

A

before code block, and after the code block until the condition = false.

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

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

A

after the code block after the final condition has happened.

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

What does the ++ increment operator do?

A

(adds one to) its operand and returns a value

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

How do you iterate through the keys of an object?

A

through a for in loops

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

How do you iterate through the keys of an object?

A

through a for in loops

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

Why do we log things to the console?

A

To see if our expected output to match

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

What is a “model”?

A

a representation of the page

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

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

A

html

71
Q

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

A

each object represents a different part of the page loaded in the browser window. data type

72
Q

What is a DOM Tree?

A

the dom specifies the way in which the browser should structure the model. an element and its child elements with all the relevant information.

73
Q

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

A
getElementsByTagName()
or querySelector('> tagname')
74
Q

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

A

getElementsByTagName()

querySelector(“h1”)

75
Q

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

A

so you can reuse it or modify it

76
Q

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

A

console.dir

77
Q

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

A

so that way it can load all the html elements first

78
Q

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

A

the first Element within the document that matches the specified selector, or group of selectors.

79
Q

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

A

a static (not live) NodeList representing a list of the document’s elements that match the specified group of selectors.

80
Q

Why do we log things to the console?

A

To make we see our expected output, and to check it’s functional

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() method

84
Q

What is a callback function

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

85
Q

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

A

after an asynchronous operation has completed

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

console log it if u arent sure, The read-only target property of the Event interface is a reference to the object onto which the event was dispatched.

87
Q

What is the difference between these two snippets of code?

A

The first one is a callback function

88
Q

What is the className property of element objects?

A

sets or returns the class name of an element

89
Q

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

A

elm.setAttribute(‘class’

90
Q

What is the textContent property of element objects?

A

sets or returns the text content of the specified node, and all its descendants

91
Q

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

A

HTML DOM textContent Property

92
Q

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

A

no

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

harder

94
Q

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

A

when you mix and match things get complicated

95
Q

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

A

focus event

96
Q

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

A

blur event

97
Q

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

A

input event

98
Q

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

A

submit event

99
Q

What does the event.preventDefault() method do?

A

Prevents browser from reloading the page

100
Q

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

A

Reloads/refreshes the page

101
Q

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

A

Elements property

102
Q

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

A

Value property

103
Q

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

A

It’s hard to see where the code went wrong.

104
Q

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

A

To see if the code is working, or to check variable values, etc.

105
Q

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

A

just creates an Element Node with the specified name

106
Q

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

A

Node.appendChild()

107
Q

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

A

name and value

108
Q

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

A

The first step is to create the node (element) you wish to append, the next is to find where you wish to append it within the document, and the final step is to actually do the appending.

109
Q

What is the textContent property of an element object for?

A

The textContent property sets or returns the text content of the specified element, and all its descendants

110
Q

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

A

setAttribute, element.className

111
Q

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

A

You can create applications that update the data of the page without needing a refresh. Also, you can create applications that are customizable by the user and then change the layout of the page without a refresh.

112
Q

What is the event.target?

A

event.target returns the where element thats being dispatched, so you can retrieve any property/ attribute that has a value

113
Q

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

A

Because of event delegation and That event listener analyzes bubbled events to find a match on child elements.

114
Q

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

A

event.target.tagName

115
Q

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

A

method searches up the DOM tree for the closest element which matches a specified element type. whatever css selector you used.

Will return itself or the matching ancestor. If no such element exists, it returns null

116
Q

How can you remove an element from the DOM?

A

remove method

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

event delegation and utilize the closest method

118
Q

What is event target

A

The read-only target property of the Event interface is 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

the affected element will disappear.

120
Q

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

A

The Element. matches() method returns true if the element would be selected by the specified selector string; returns a boolean

121
Q

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

A

The getAttribute() method of the Element interface returns the value of a specified attribute on the element.

122
Q

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

A

declaring, and changing a var

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

spaghetti

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

spaghetti

125
Q

What is JSON?

A

JSON stands for JavaScript Object Notation

JSON is a lightweight format for storing and transporting data

JSON is often used when data is sent from a server to a web page

126
Q

What are serialization and deserialization?

A

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory.

127
Q

Why are serialization and deserialization useful?

A

can be serialized on one platform and deserialized on an entirely different platform. Serialization allows the developer to save the state of an object and re-create it as needed, providing storage of objects as well as data exchange. T

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

JSON.parse

130
Q

How to you store data in localStorage?

A

Window.localStorage

131
Q

How to you retrieve data from localStorage?

A

getItem method of the localStorage object

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

procedure associated with a message and an object.

135
Q

How to declare a method

A

create an object, each property will declare a function with parameters, within the function, return in what you wanna do.

136
Q

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

A

A method is a function which is a property of an object. There are two kind of methods: Instance Methods which are built-in tasks performed by an object instance, or Static Methods which are tasks that are called directly on an object constructor.

137
Q

Describe method call syntax (structure).

A

assign a function to a object property.

138
Q

How is a method different from any other function?

A

A method, like a function, is a set of instructions that perform a task. The difference is that a method is associated with an object, while a function is not.

139
Q

What is the defining characteristic of Object-Oriented Programming?

A

Object-oriented methodology relies on three characteristics that define object-oriented languages: encapsulation, polymorphism, and inheritance.

140
Q

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

A

Encapsulation, Abstraction, Inheritance, and Polymorphism.

141
Q

What is “abstraction”?

A

is the process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics. the turn off light example. takes something complex, make it easy.

142
Q

What does API stand for?

A

Application programming interface

143
Q

What is the purpose of an API?

A

allows apps to send information between each other. While there are numerous protocols and technologies involved, the underlying purpose of APIs is always the same: to let one piece of software communicate with another.

144
Q

What is this in JavaScript?

A

it’s an implicit parameter, 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.

145
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.

146
Q

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

A

call time

147
Q

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

A

if you cannot see the function being called, then you do not know what the value of this will be.

148
Q

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

A

the value of this can be recognized as “the object to the left of the dot” when the function is called (as a method). if not, the value of this can be recognized as “the object to the left of the dot” when the function is called (as a method).

149
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal inheritance

150
Q

What is a prototype in JavaScript?

A

Prototypes are the mechanism by which JavaScript objects inherit features from one another. to provide inheritance, objects can have a prototype object, which acts as a template object that it inherits methods and properties from.

151
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

those methods are defined on a “prototype” object and arrays simply borrow those methods when they’re needed.

152
Q

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

A

looks through the in the prototype chain, and borrows it from the object.

153
Q

What does the new operator do?

A

The new operator 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.

154
Q

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

A

prototype property

155
Q

What does the instanceof operator do?

A

used to test if an object is of a given type. useful for testing

156
Q

What is a “callback” function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

157
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 the setTimeout()

158
Q

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

A

by using setInterval and calling a function every second

159
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0 seconds after code has been read and run

160
Q

What do setTimeout() and setInterval() return?

A

The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval()

161
Q

What is Array.prototype.filter useful for?

A

creates a new array that’s been trimmed down

162
Q

What is Array.prototype.map useful for?

A

creates a new array populated with the results of calling a provided function on every element in the calling array.

163
Q

What is Array.prototype.reduce useful for?

A

Combining the elements of an array into a single value.

164
Q

What is “syntactic sugar”?

A

A cleaner way of writing something

165
Q

What is the typeof an ES6 class?

A

function

166
Q

Describe ES6 class syntax.

A

use the keyword class, give it a name which is typically uppercased, (cause it’s a pattern for something like XML), add in an optional constructor within the code block with optional parameters, the constructor is a function that gets executed immediately whenever a new thing get instantiated.

inside the constructor function, have whatever the parameter is being assigned to the parameter of this object.

then inside the class code block: you can throw in whatever methods you want, which is shorthand syntax.

167
Q

Describe ES6 class syntax

A

use the keyword class, give it a name which is typically uppercased, (cause it’s a pattern for something like XML), add in a constructor within the code block with relevant parameters, the constructor is a function that gets executed immediately whenever a new thing get instantiated.

inside the constructor function, have whatever the parameter is being assigned to the parameter of this object.

then inside the class code block: you can throw in whatever methods you want, which is shorthand syntax. in there you can do whatever.

168
Q

What is “refactoring”?

A

changing code, without changing it’s external behavior. intended to improve the design, structure, and/or implementation of the software

169
Q

What does fetch() return?

A

returns the data of the format JSON, also it lets you know if your promised failed if you had invalid input

returns a promise, then use then or catch

170
Q

What is the default request method used by fetch()?

A

GET

171
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

use object literal, method property within that code block

172
Q

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A

the return of the inner function.

173
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

closures

174
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

when it is defined