JavaScript Flashcards

Up until learning about OOP and ES6 and the event loop

1
Q

What is the purpose of variables?

A

To store data for use later on

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

How do you declare a variable?

A

Var keyword and variable name

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

Variable Name = Variable Value

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, underscore, dollar sign, numbers (can’t start with this)

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

There must be consistency in the way names are typed with capitalization

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

Safe enclosure for text data. Add new content to a page.

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

For math and other tasks like size of screen, moving the position of an element on a page, or setting the amount of time an element should take to fade in.

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

Generates true or false to determine which part of script should run

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

Storing Values

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

Variable name = new value

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: can only exist if it is purposely assigned; acts as a purposeful empty much like a placeholder
Undefined: this is something uses to say nothing or ‘I don’t know’

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

Easier for debugging

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

Numeric

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

What is string concatenation?

A

Using the concatenation operator (+)

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

Concatenation and Math

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

The current value of variable + new value is a result of the new value of the original variable.

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

What are objects used for?

A

Grouped data of a set of variables and functions in relation to each other

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

What are object properties?

A

Variables that are part of an object

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

Describe object literal notation.

A

Curly braces with 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

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 notation and square 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

Making lists of related data as the same type

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

Describe array literal notation.

A

[ ] with comma separated values

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

Array: numbered indexes, uses [ ], has order and is less customizable
Objects: has properties, alphanumerical, uses { }, has no order and has more ability to be changed

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

Total number of values in an 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 property of an array - 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

Reusable block of code instead of always repeating a set of instructions.

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
Name (Optional)
Parameter (Optional)
Code Block
Return Value (Optional)
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

Function name and argument

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 calls do not have the code block and function keyword

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

Parameter - used for function definition

Arguments - used for function call

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

Why are function parameters useful?

A

Allows the function to be more reusable by giving you more clarity on what arguments need to be called.

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

Stops function and gives return value.

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 work and to debug

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

What is a method?

A

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

Methods have a . with an object. We need to know where the function is coming from

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

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

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

Math.random - generates 0 to 1 usually used for percentage to multiply against

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

.splice ( ) leaving out the parameters of item1, item2, item3 etc.

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

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

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

No. You can check through console.log or MDN

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

A lot

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 not all the time sometimes it is just part of the sequence of steps.

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

A lot

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

Helps code 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 not all the time

55
Q

Describe the syntax (structure) of an if statement.

A

If key word with a initializer, condition, and final expression in parenthesis followed by the conditional in { }

56
Q

What are the three logical operators?

A

&&, ||, !

57
Q

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

A

&&, ||

58
Q

What is the purpose of a loop?

A

Repeats a chunk of code until the condition is met

59
Q

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

A

Helps us stop the loop

60
Q

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

A

Each time code block runs

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

In the beginning once

63
Q

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

A

After the final expression and before each iteration

64
Q

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

A

After each 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 1 to whatever the current value is

67
Q

How do you iterate through the keys of an object?

A

for…in loop

68
Q

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

A

focus

69
Q

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

A

blur

70
Q

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

A

input

71
Q

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

A

submit

72
Q

What does the event.preventDefault() method do?

A

This prevents the default behavior of the element

73
Q

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

A

The page will refresh because the data of the form is being sent no where so it sends it to the page itself which will cause a reload.

74
Q

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

A

.elements

75
Q

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

A

.value

76
Q

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

A

If it does not work it will be hard to spot the bug

77
Q

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

A

You will know when things need to be fixed

78
Q

What is the event.target?

A

Element where event occurs

79
Q

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

A

Hides element from viewport and is removed from document flow

80
Q

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

A

String for CSS selector and returns a boolean

81
Q

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

A

getAttribute

82
Q

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

A

Every step to check your work

83
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 to put event listeners on each individual tab which would not be sustainable

84
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

You would have a huge condition block which would need to be updates frequently if changed were made to the views

85
Q

What is JSON?

A

It is a data interchange format

86
Q

What are serialization and deserialization?

A

Serialization - turns object to a stream of bytes. Takes data and turns it into order
Deserialization - takes stream of bytes and turns it into an object. This is a format that we can work with

87
Q

Why are serialization and deserialization useful?

A

For sending data over the network

88
Q

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

A

JSON.stringify

89
Q

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

A

JSON.parse

90
Q

How do you store data in localStorage?

A

setItem method

91
Q

How to you retrieve data from localStorage?

A

getItem method

92
Q

What data type can localStorage save in the browser?

A

Strings

93
Q

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

A

When the window, the document and its resources are about to be unloaded.

94
Q

What is a “callback” function?

A

Function being passed as an argument

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

96
Q

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

A

setInterval ( ) method

97
Q

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

A

0 - meaning execute “immediately” or more accurately on the next event cycle

98
Q

What do setTimeout() and setInterval() return?

A

Returns a number ID

99
Q

What is AJAX?

A

Allows you to request data from a server and load it

100
Q

What does the AJAX acronym stand for?

A

Asynchronous Javascript and XML

101
Q

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

A

XMLHttpRequest

102
Q

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

A

Load Event

103
Q

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

A

They both share a prototype

104
Q

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

A

Code between two curly braces (ex: in if conditions, loops, function)

105
Q

What does block scope mean?

A

Area within if, switch conditions or for and while loops.

106
Q

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

A

Block scope

107
Q

What is the difference between let and const?

A

let can be reassigned while const cannot

108
Q

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

A

Because you can change the contents of it but you cannot actually reassign the whole variable

109
Q

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

A

Use let if you need to reassign. Use const if you don’t need to reassign.

110
Q

What is the syntax for writing a template literal?

A

${...}

111
Q

What is “string interpolation”?

A

Ability to embed variables inside a string

112
Q

What is destructuring, conceptually?

A

Assigning properties and objects to individual variables

113
Q

What is the syntax for Object destructuring?

A

const/let/var {list of properties} = Object (you want to deconstruct)

114
Q

What is the syntax for Array destructuring?

A

const/let/var [list of elements] = Name of array (you want to deconstruct)

115
Q

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

A

Placement of the brackets in respect to = is important:
Creating usually means brackets are on the right side of the = while deconstructing means brackets are on the left side of the =

116
Q

What is the syntax for defining an arrow function?

A
0 parameters ( ) =>
1 parameter (parameter) =>
Multiple parameters (parameter, parameter) =>
117
Q

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

A

Nothing however, if you have multiple lines of code you need the curly braces

118
Q

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

A

It will be defined in the surrounding scope the arrow is defined in

119
Q

What is the JavaScript Event Loop?

A

Responsible for executing code, processing events, and executing queued tasks.

120
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

Blocking is synchronous

Non-blocking is asynchronous

121
Q

What are the three states a Promise can be in?

A

Pending, fulfilled, rejected

122
Q

How do you handle the fulfillment of a Promise?

A

then method

123
Q

How do you handle the rejection of a Promise?

A

catch method

124
Q

What is Array.prototype.filter useful for?

A

Truncates list depending on specific criteria

125
Q

What is Array.prototype.map useful for?

A

When you want a new array with every element changed

126
Q

What is Array.prototype.reduce useful for?

A

Combining an array to a single value

127
Q

What is “syntactic sugar”?

A

Primarily for aesthetics - makes code easier to understand and more readable

128
Q

What is the typeof an ES6 class?

A

Function

129
Q

Describe ES6 class syntax

A
class OptionalName {
constructor()
optionalMethods()
}
130
Q

What is “refactoring”?

A

Rewriting and restructuring code for sustainability and viability while preserving original behavior

131
Q

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

A

A function

132
Q
What does this code do?
const wrap = value => () => value;
A

Defines a function that takes an argument and returns a function that will return an argument.

133
Q

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

A

Defined

134
Q

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

A

Closures