Javascript Flashcards

1
Q

What is the purpose of variables?

A

To store data to use again in the future.

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

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

A

var keyword var name = var value;

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

What characters are allowed in variable names?

A

Letters, Numbers, Underscore, and dollarsign.

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

What does the = operator mean in JavaScript?

A

Assignment.

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

Uppercase and lowercase variable names are not equal,

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

sequence of characters that represent text

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

represents a numeric data type that allows us to perform mathematical operations on it

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

Lets the computers ultimately decide what to do or not do.

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

What is the difference between null and undefined?

A

undefined: JavaScript’s method of saying “empty”
null: developer’s way of saying “empty”; assigned intentionally

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

What is string concatenation?

A

adding two strings together

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

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

A

adds/concatenates the value on the right with the value on the left and then assigns it to the variable on the left.

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

What are objects used for?

A

to group relevant data together

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

What are object properties?

A

variables that live within an object

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

Describe object literal notation.

A

var keyword var name = { };

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

How do you remove a property from an object?

A

Using the delete operator

delete object.property

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

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

A

dot notation (object.property = value)

bracket notation (object[‘property’] = value)

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

What are arrays used for?

A

Useful when working with lists or groups of similar data

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

Describe array literal notation.

A

var varName = [list contents (separated by comma)]

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

How are arrays different from “plain” objects?

A

values assigned to index numbers rather than keys

order is preserved in arrays

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

What is the length property of an array?

A

returns how many things are stored in the list

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

How do you calculate the last index of an array?

A

array.length - 1

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

Give five examples of JavaScript primitives.

A

Number, Boolean, String, Null, Undefined

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

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

A

To know which variable you are logging.

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

How do you update the value of a variable?

A

var name = new value;

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

How do you declare a variable?

A

Var keyword var name;

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 block of code that has a specific purpose and can be reused as many times as needed

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 functionName (optional Parameter) {
optional Return;
}
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

functionName( );

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

What is the difference between a parameter and an argument?

A

Functions are defined with parameters and called with arguments.

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

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

A

Causes the function to produce a value and also exits the function.

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

Why are function parameters useful?

A

Can achieve different results depending on the data passed in

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

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

A

Function definition has parameters and a code block and function call has arguments.

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 check if the value received is as expected.

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

What is a method?

A

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

They are accessed using dot notation.

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

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

A

Math.floor( )

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

How do you generate a random number?

A

Math.Random( )

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

How do you delete an element from an array?

A

Array.splice( )

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

How do you append an element to an array?

A

Array.push( )

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

How do you break a string up into an array?

A

String.split( )

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

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

A

No, string are immutable. Console log.

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

Roughly how many string 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
47
Q

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

A

35.

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

No.

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

How do you remove the last element from an array?

A

Array.pop( )

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

To make a decision

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 (condition){
code to be exectuted;
}

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

What are the three logical operators?

A

logical And (&&), Logical Or ( || ), Logical Not ( ! )

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

&& or | |

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

Repeat code until 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 tell the loop when to stop running.

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

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

A

One full pass of the loops code block.

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

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

A

Before each Iteration.

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

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

A

Once, before the loop begins.

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

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

A

After the final expression and before each iteration.

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

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

A

After each iteration.

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

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

What does the ++ increment operator do?

A

Increments by 1.

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

For in loop.

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

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

A

Focus event

69
Q

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

A

Blur event

70
Q

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

A

Input event

71
Q

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

A

Submit event

72
Q

What does the event.preventDefault() method do?

A

Prevents the page from automatically reloading.

73
Q

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

A

Refreshes the page.

74
Q

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

A

Elements property.

75
Q

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

A

Value property.

76
Q

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

A

There may have been an error that you didn’t notice and have to re write the code.

77
Q

What is the event.target?

A

The element on which the event occurred.

78
Q

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

A

Hides the element from the page.

79
Q

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

A

CSS selector and returns a boolean value.

80
Q

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

A

getAttribute( )

81
Q

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

A

Every step.

82
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

Every element would have an event listener on it.

83
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

With multiple if statements.

84
Q

What is JSON?

A

A data interchange format.

85
Q

What are serialization and deserialization?

A

Serialization - turning an object into bytes.

Deserialization - turning bytes into an object.

86
Q

Why are serialization and deserialization useful?

A

To send data over a network.

87
Q

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

A

JSON.stringify( )

88
Q

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

A

JSON.parse( )

89
Q

How do you store data in localStorage?

A

localStorage.setItem( )

90
Q

How do you retrieve data from localStorage?

A

localStorage.getItem( )

91
Q

What data type can localStorage save in the browser?

A

Strings.

92
Q

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

A

Closing tab or refreshing page.

93
Q

What is a method?

A

A function that is a property of an object.

94
Q

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

A

Definition is a function. being assigned to a property. Call is methodName.property( ).

95
Q

Describe method definition syntax (structure).

A

property: function (optional parameters)

96
Q

Describe method call syntax (structure).

A

Object.methodName( )

97
Q

How is a method different from any other function?

A

Method is attached to an object. Function is on its own.

98
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism.

99
Q

What is “abstraction”?

A

Working with complex things in a simple way.

100
Q

What does API stand for?

A

application programming interface

101
Q

What is the purpose of an API?

A

Allows computers to communicate to each other.

102
Q

What is this in JavaScript?

A

A variable that holds a value which is the name of the object you are working in.

103
Q

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

A

It is available in a functions code block even though it was never included in the functions parameter list or declared with var.

104
Q

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

A

Call time.

105
Q

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

A

You don’t know what the value will be.

106
Q

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

A

the object to the left of the dot or the global window object.

107
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal Inheritance.

108
Q

What is a prototype in JavaScript?

A

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

109
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

They look for the prototype.

110
Q

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

A

On the prototype.

111
Q

What does the new operator do?

A

Creates a blank object, adds a property to the new object (proto), binds the newly created object instance as this, returns this if the function doesn’t return an object.

112
Q

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

A

Prototype.

113
Q

What does the instanceof operator do?

A

Checks if the prototype property of a constructor appears in the prototype chain of an object.

114
Q

What is a “callback” function?

A

A function that is passed into another function as an argument.

115
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

setTimeout( )

116
Q

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

A

setInterval( )

117
Q

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

A

0

118
Q

What do setTimeout() and setInterval() return?

A

A numeric Id.

119
Q

What is a client?

A

A piece of computer hardware or software asks for something.

120
Q

What is a server?

A

A piece of computer hardware or software that gives a response to the client.

121
Q

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

A

GET

122
Q

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

A

Protocol version, status code, and status text.

123
Q

What are HTTP headers?

A

lets the client and the server pass additional information with an HTTP request or response

124
Q

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

A

MDN

125
Q

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

A

No.

126
Q

What is AJAX?

A

It allows users to still use the page while requests are being made.

127
Q

What does the AJAX acronym stand for?

A

Asynchronous Javascript and XML.

128
Q

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

A

XMLHttpRequest

129
Q

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

A

load

130
Q

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

A

receiving the response is an event and event targets include objects that support events.

131
Q

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

A

They share prototype.

132
Q

What is a code block? What are some examples of a code block?

A

Inside of curly braces. Function code block, conditional code block, for loop code block…

133
Q

What does block scope mean?

A

Variable only exists within the code block.

134
Q

What is the scope of a variable declared with const or let?

A

Block scoped.

135
Q

What is the difference between let and const?

A

Let can be reassigned and Const cannot be reassigned.

136
Q

Why is it possible to .push() a new value into a const variable that points to an Array?

A

You can change the arrays elements but not reassign the array to another array.

137
Q

How should you decide on which type of declaration to use?

A

If you know you will not change the value of the variable, use Const. Use, Let when you need to change a value of a variable.

138
Q

What is the syntax for writing a template literal?

A

Wrap text in back-ticks. variables are in ${var}.

139
Q

What is “string interpolation”?

A

Placing variables and expressions within the string and Javascript will replace them with their values.

140
Q

What is destructuring, conceptually?

A

Unpacking values from arrays or properties of an objects into variables.

141
Q

What is the syntax for Object destructuring?

A

const keyword {property names} = object variable name

142
Q

What is the syntax for Array destructuring?

A

const keyword [index#/var names] = array variable name

143
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

Placements of the brackets in respect to destructuring or creating.

144
Q

What is the syntax for defining an arrow function?

A

var keyword functionName = (parameters) => expression

145
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

There can only be an expression (no statements).

146
Q

How is the value of this determined within an arrow function?

A

The value of this is inherited from the surrounding scope it was defined in.

147
Q

What is a CLI?

A

Command line interface

148
Q

What is a GUI?

A

Graphical user interface

149
Q

Give at least one use case for each of the commands listed in this exercise.

A
man - checking manual
cat - Concatenates files / Prints contents of file.
ls - check list of contents in directory
pwd - verify the current directory you are in
echo - Displays line of text
touch - Changes file timestamps.
mkdir - Create new directory
mv - rename directories and moves them.
rm - delete file or directory
cp - Copy a file
150
Q

What is Node.js?

A

A program that allows Js to be run outside of a browser.

151
Q

What are the three states a Promise can be in?

A

Pending, fulfilled, rejected

152
Q

How do you handle the fulfillment of a Promise?

A

then method (function)

153
Q

How do you handle the rejection of a Promise?

A

catch()

154
Q

What is Array.prototype.filter useful for?

A

Getting rid of elements in array that do not pass the test in the function / finding certain elements

155
Q

What is Array.prototype.map useful for?

A

Calling a function for each element in the array

156
Q

What is Array.prototype.reduce useful for?

A

Combine elements of an array to a single value

157
Q

What is “syntactic sugar”?

A

A way of writing code in a way that is easier to read or express that, if removed, would not effect the language functionality

158
Q

What is the typeof an ES6 class?

A

checks if the class is a function

159
Q

Describe ES6 class syntax.

A
class keyword functionName{
constructor(name){
this.name = name
}
}
160
Q

What is “refactoring”?

A

Restructuring existing code without changing its behavior

161
Q

What does fetch() return?

A

A promise

162
Q

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

A

GET

163
Q

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

A

fetch(url, object with method property with value set to which method you are using)

164
Q

When does React call a component’s componentDidMount method?

A

Immediately after a component is rendered for the first successful render

165
Q

Name three React.Component lifecycle methods.

A

Constructor, Render, componentDidMount

166
Q

How do you pass data to a child component?

A

props

167
Q

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

A

when it is defined.

168
Q

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

A

closures - lexical scoping. Inner function have access to variables declared in their outer scope.