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
Describe array literal notation.
[ ] with comma separated values
26
How are arrays different from "plain" objects?
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
27
What number represents the first index of an array?
0
28
What is the length property of an array?
Total number of values in an array
29
How do you calculate the last index of an array?
Length property of an array - 1
30
What is a function in JavaScript?
Reusable block of code instead of always repeating a set of instructions.
31
Describe the parts of a function definition.
``` Function Keyword Name (Optional) Parameter (Optional) Code Block Return Value (Optional) ```
32
Describe the parts of a function call.
Function name and argument
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function calls do not have the code block and function keyword
34
What is the difference between a parameter and an argument?
Parameter - used for function definition | Arguments - used for function call
35
Why are function parameters useful?
Allows the function to be more reusable by giving you more clarity on what arguments need to be called.
36
What two effects does a return statement have on the behavior of a function?
Stops function and gives return value.
37
Why do we log things to the console?
To check work and to debug
38
What is a method?
A function which is a property of an object
39
How is a method different from any other function?
Methods have a . with an object. We need to know where the function is coming from
40
How do you remove the last element from an array?
.pop( )
41
How do you round a number down to the nearest integer?
Math.floor( )
42
How do you generate a random number?
Math.random - generates 0 to 1 usually used for percentage to multiply against
43
How do you delete an element from an array?
.splice ( ) leaving out the parameters of item1, item2, item3 etc.
44
How do you append an element to an array?
.push ( )
45
How do you break a string up into an array?
.split ( )
46
Do string methods change the original string? How would you check if you weren't sure?
No. You can check through console.log or MDN
47
Roughly how many string methods are there according to the MDN Web docs?
A lot
48
Is the return value of a function or method useful in every situation?
No not all the time sometimes it is just part of the sequence of steps.
49
Roughly how many array methods are there according to the MDN Web docs
A lot
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
51
Give 6 examples of comparison operators.
==, !=, ===, !==, , >=, <=
52
What data type do comparison expressions evaluate to?
Boolean
53
What is the purpose of an if statement?
Helps code make a decision
54
Is else required in order to use an if statement?
No not all the time
55
Describe the syntax (structure) of an if statement.
If key word with a initializer, condition, and final expression in parenthesis followed by the conditional in { }
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
&&, ||
58
What is the purpose of a loop?
Repeats a chunk of code until the condition is met
59
What is the purpose of a condition expression in a loop?
Helps us stop the loop
60
What does "iteration" mean in the context of loops?
Each time code block runs
61
When does the condition expression of a while loop get evaluated?
Before each iteration
62
When does the initialization expression of a for loop get evaluated?
In the beginning once
63
When does the condition expression of a for loop get evaluated?
After the final expression and before each iteration
64
When does the final expression of a for loop get evaluated?
After each iteration
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break
66
What does the ++ increment operator do?
Adds 1 to whatever the current value is
67
How do you iterate through the keys of an object?
for...in loop
68
What event is fired when a user places their cursor in a form control?
focus
69
What event is fired when a user's cursor leaves a form control?
blur
70
What event is fired as a user changes the value of a form control?
input
71
What event is fired when a user clicks the "submit" button within a ?
submit
72
What does the event.preventDefault() method do?
This prevents the default behavior of the element
73
What does submitting a form without event.preventDefault() do?
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
What property of a form element object contains all of the form's controls.
.elements
75
What property of form a control object gets and sets its value?
.value
76
What is one risk of writing a lot of code without checking to see if it works so far?
If it does not work it will be hard to spot the bug
77
What is an advantage of having your console open when writing a JavaScript program?
You will know when things need to be fixed
78
What is the event.target?
Element where event occurs
79
What is the affect of setting an element to display: none?
Hides element from viewport and is removed from document flow
80
What does the element.matches() method take as an argument and what does it return?
String for CSS selector and returns a boolean
81
How can you retrieve the value of an element's attribute?
getAttribute
82
At what steps of the solution would it be helpful to log things to the console?
Every step to check your work
83
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?
You would have to put event listeners on each individual tab which would not be sustainable
84
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?
You would have a huge condition block which would need to be updates frequently if changed were made to the views
85
What is JSON?
It is a data interchange format
86
What are serialization and deserialization?
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
Why are serialization and deserialization useful?
For sending data over the network
88
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify
89
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
90
How do you store data in localStorage?
setItem method
91
How to you retrieve data from localStorage?
getItem method
92
What data type can localStorage save in the browser?
Strings
93
When does the 'beforeunload' event fire on the window object?
When the window, the document and its resources are about to be unloaded.
94
What is a "callback" function?
Function being passed as an argument
95
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?
setTimeout ( ) method
96
How can you set up a function to be called repeatedly without using a loop?
setInterval ( ) method
97
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 - meaning execute "immediately" or more accurately on the next event cycle
98
What do setTimeout() and setInterval() return?
Returns a number ID
99
What is AJAX?
Allows you to request data from a server and load it
100
What does the AJAX acronym stand for?
Asynchronous Javascript and XML
101
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
102
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
Load Event
103
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They both share a prototype
104
What is a code block? What are some examples of a code block?
Code between two curly braces (ex: in if conditions, loops, function)
105
What does block scope mean?
Area within if, switch conditions or for and while loops.
106
What is the scope of a variable declared with const or let?
Block scope
107
What is the difference between let and const?
let can be reassigned while const cannot
108
Why is it possible to .push() a new value into a const variable that points to an Array?
Because you can change the contents of it but you cannot actually reassign the whole variable
109
How should you decide on which type of declaration to use?
Use let if you need to reassign. Use const if you don't need to reassign.
110
What is the syntax for writing a template literal?
`${...}`
111
What is "string interpolation"?
Ability to embed variables inside a string
112
What is destructuring, conceptually?
Assigning properties and objects to individual variables
113
What is the syntax for Object destructuring?
const/let/var {list of properties} = Object (you want to deconstruct)
114
What is the syntax for Array destructuring?
const/let/var [list of elements] = Name of array (you want to deconstruct)
115
How can you tell the difference between destructuring and creating Object/Array literals?
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
What is the syntax for defining an arrow function?
``` 0 parameters ( ) => 1 parameter (parameter) => Multiple parameters (parameter, parameter) => ```
117
When an arrow function's body is left without curly braces, what changes in its functionality?
Nothing however, if you have multiple lines of code you need the curly braces
118
How is the value of this determined within an arrow function?
It will be defined in the surrounding scope the arrow is defined in
119
What is the JavaScript Event Loop?
Responsible for executing code, processing events, and executing queued tasks.
120
What is different between "blocking" and "non-blocking" with respect to how code is executed?
Blocking is synchronous | Non-blocking is asynchronous
121
What are the three states a Promise can be in?
Pending, fulfilled, rejected
122
How do you handle the fulfillment of a Promise?
then method
123
How do you handle the rejection of a Promise?
catch method
124
What is Array.prototype.filter useful for?
Truncates list depending on specific criteria
125
What is Array.prototype.map useful for?
When you want a new array with every element changed
126
What is Array.prototype.reduce useful for?
Combining an array to a single value
127
What is "syntactic sugar"?
Primarily for aesthetics - makes code easier to understand and more readable
128
What is the typeof an ES6 class?
Function
129
Describe ES6 class syntax
``` class OptionalName { constructor() optionalMethods() } ```
130
What is "refactoring"?
Rewriting and restructuring code for sustainability and viability while preserving original behavior
131
What must the return value of myFunction be if the following expression is possible? myFunction()();
A function
132
``` What does this code do? const wrap = value => () => value; ```
Defines a function that takes an argument and returns a function that will return an argument.
133
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
Defined
134
What allows JavaScript functions to "remember" values from their surroundings?
Closures