Javascript Flashcards

1
Q

What is the purpose of variables?

A

To temporarily store a value in a 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 the var keyword

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

with the assignment operator followed by a 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, numbers(but not first), underscores, and dollar signs.

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

each letter, undercase and lowercase, has a different ASCII value.

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

to store words and shit

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

to store number

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

to store either a true or false value that will determine the outcome of certain decisions in your program.

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

it is the assignment operator that will assign a value to a variable.

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

by initializing it with no var keyword.

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 is an assigned blank value while undefined is a not yet defined value.

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

it makes code reading easier

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

Give five examples of JavaScript primitives.

A

number, string, 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

a number

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

What is string concatenation?

A

combining strings with an addition sign

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

both adds numbers and concatenates strings

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

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

it adds the value, or expression, to the right of the equals sign to value of the variable to the left and then assigns that value to the variable.

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

What are objects used for?

A

to store related data and put together a type of model of some sort.

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

Describe object literal notation.

A

after var assignment opening curly brace followed by the key of the property then a colon then the value of that property. Each of those properties are separated by commas. End with a closing curly brace.

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

the delete keyword and the property

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

for lists that don’t need to be ordered

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
after var assignment opening bracket then values separated by commas then closing bracket
26
How are arrays different from "plain" objects?
they use the index system instead of keys.
27
What number represents the first index of an array?
0
28
What is the length property of an array?
array.length and it gives the length of the array.
29
How do you calculate the last index of an array?
array.length - 1.
30
What is a function in JavaScript?
A set of code that is declared to complete a specific task
31
Describe the parts of a function definition.
the function key word, the name of the function, parameters if any, then the code block
32
Describe the parts of a function call.
the function name followed by arguments if any then a semi colon.
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
a function call is when a function is to be used, the function definition is when a function is to be declared.
34
What is the difference between a parameter and an argument?
a parameter is the place holder variable in the function definition that will replaced when the function is called by the arguments listed in the function call. arguments are in the function call.
35
Why are function parameters useful?
the way to provide data for the functions and give different results so that the functions can be used in a variety of cases.
36
What two effects does a return statement have on the behavior of a function?
it both returns data to the function then stops the function.
37
Why do we log things to the console?
for debugging purposes to catch mistakes.
38
What is a method?
a function attached to an object
39
How is a method different from any other function?
it directly modifies the thing it is attached to. other than that they are the same
40
How do you remove the last element from an array?
using the pop method
41
How do you round a number down to the nearest integer?
using the math object with the floor method
42
How do you generate a random number?
using the math object with the random method
43
How do you delete an element from an array?
using the splice method on your array.
44
How do you append an element to an array?
using the push method on your array
45
How do you break a string up into an array?
using the split method with a string of a single space as your argument
46
Do string methods change the original string? How would you check if you weren't sure?
no they only affect the return value. You can check by logging the original string to the console.
47
Is the return value of a function or method useful in every situation?
no, you don't need to use it if you don't have to.
48
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
49
Give 6 examples of comparison operators.
>, =, ===, !==, <=
50
What data type do comparison expressions evaluate to?
boolean
51
What is the purpose of an if statement?
to give multiple paths for a conditional statement
52
Is else required in order to use an if statement?
no
53
Describe the syntax (structure) of an if statement.
the key word if followed by the conditional expression and then the code block
54
What are the three logical operators?
&&, ||, !
55
How do you compare two different expressions in the same condition?
with logical operators.
56
What is the purpose of a loop?
to repeat a certain section of code if necessary
57
What is the purpose of a condition expression in a loop?
to give that loop an exit route.
58
What does "iteration" mean in the context of loops?
how many times the loop runs
59
When does the condition expression of a while loop get evaluated?
before each iteration
60
When does the initialization expression of a for loop get evaluated?
its the very first step
61
When does the condition expression of a for loop get evaluated?
before each loop iteration runs
62
When does the final expression of a for loop get evaluated?
after the loop code block is excecated
63
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
64
What does the ++ increment operator do?
adds 1 and assigns it to the variable
65
How do you iterate through the keys of an object?
a for in loop
66
Which "document" is being referred to in the phrase Document Object Model?
the HTML document
67
What is the word "object" referring to in the phrase Document Object Model?
Objects in the JavaScript language
68
What is a DOM Tree?
a tree representation of an HTML document
69
Give two examples of document methods that retrieve a single element from the DOM.
getElementByID, and querySelector
70
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll
71
Why might you want to assign the return value of a DOM query to a variable?
because if used more than once it doesn't have to retrieve the return address of a DOM query multiple times.
72
What console method allows you to inspect the properties of a DOM element object?
dir
73
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
so all the HTML could run first
74
What does document.querySelector() take as its argument and what does it return?
takes a string of the tag name, class, or id as a CSS selector. It returns the first element it finds that matches that selector
75
What does document.querySelectorAll() take as its argument and what does it return?
takes a string of a CSS selector. It returns a node list of all the elements under that selector
76
What is the purpose of events and event handling?
It is a way for the user to interact with the webpage and potentially change the style of the page and many other things.
77
What do [] square brackets mean in function and method syntax documentation?
its optional
78
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener
79
What is a callback function?
A callback function is a function passed into another function as an argument
80
What object is passed into an event listener callback when the event fires?
an event object built by JavaScript.
81
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
It is the element object from where the event originated from. you could console.log the event object and check, or look it up in MDN
82
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick())
the first waits to execute the function until that element node is clicked, while the second one executes before the webpage is loaded.
83
What is the className property of element objects?
gets and sets the value of the class attribute of the specified element.
84
How do you update the CSS class attribute of an element using JavaScript?
by using the className property on the event variable and setting it equal to the class name in a string.
85
What is the textContent property of element objects?
represents the text content of the node and its descendants.
86
How do you update the text within an element using JavaScript?
by using the textContent property on the event variable and setting it equal to the text you desire
87
Is the event parameter of an event listener callback always useful?
no
88
Why is storing information about a program in variables better than only storing it in the DOM?
It cuts back execution time because JavaScript doesn't constantly have to fetch all the elements it needs to use, it just uses the stored addresses in the variable assigned.
89
What event is fired when a user places their cursor in a form control?
the focus event
90
What event is fired when a user's cursor leaves a form control?
the blur event
91
What event is fired as a user changes the value of a form control?
the input event
92
What does the event.preventDefault() method do?
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.
93
What does submitting a form without event.preventDefault() do?
it refreshes the page
94
What property of a form element object contains all of the form's controls.
elements
95
What property of form a control object gets and sets its value?
value
96
What is an advantage of having your console open when writing a JavaScript program?
You can see when and where mistakes happen
97
What event is fired when a user clicks the "submit" button within a ?
the submit event
98
Does the document.createElement() method insert a new element into the page?
no it just creates an element
99
How do you add an element as a child to another element?
appendChild method
100
What do you pass as the arguments to the element.setAttribute() method?
the attribute name and the value
101
What steps do you need to take in order to insert a new element into the page?
creating the element, query the element you want to append it to, then append the element you created to the node you queried.
102
What is the textContent property of an element object for?
to either retrieve the text, or assign the element some text value
103
Name two ways to set the class attribute of a DOM element.
use the setAttribute method, or assign a new name to the className property.
104
What are two advantages of defining a function to create something (like the work of creating a DOM tree)?
it is both reusable and condenses code.
105
What is the affect of setting an element to display: none?
you can no longer see nor interact with said element and it is no longer in document flow.
106
What does the element.matches() method take as an argument and what does it return?
it takes a string of a CSS selector and returns a boolean of whether or not the selector is the same value
107
How can you retrieve the value of an element's attribute?
by using the getAttribute method
108
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?
using an eventListener on every node in that tab that needs to be added
109
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?
comparing each class name at the index starting from 0 to the length of the node list one by one manually.
110
What is JSON?
JSON is a text-based data format following JavaScript object syntax
111
What are serialization and deserialization?
Serialization is the process of turning an object in memory into a stream of bytes Deserialization is the reverse process: turning a stream of bytes into an object in memory.
112
Why are serialization and deserialization useful?
You can do stuff like store it on disk or send it over the network.
113
How do you serialize a data structure into a JSON string using JavaScript?
using the JSON.stringify method with the data as the argument
114
How do you deserialize a JSON string into a data structure using JavaScript?
with the JSON.parse method with the JSON string as the argument.
115
How to you store data in localStorage?
by using the setItem method on the localStorage object
116
How to you retrieve data from localStorage?
by using the getItem method on the localStorage object
117
What data type can localStorage save in the browser?
only strings or null
118
When does the 'beforeunload' event fire on the window object?
right before the webpage is either reloaded or exited.
119
How can you tell the difference between a method definition and a method call?
method definitions use the function keyword and are ended with a code block for defining the function. method calls use that method of the property it is attached to followed by parentheses and arguments in that if needed.
120
Describe method definition syntax (structure).
method definitions have the function keyword, followed by the function name, followed by any parameters within parentheses, followed by the definition block
121
Describe method call syntax (structure).
method calls are attached to the property it is used on and are followed by parameters incased in parentheses if any.
122
How is a method different from any other function?
a method can be used on objects while functions cannot.
123
What is the defining characteristic of Object-Oriented Programming?
That objects can contain both data (as properties) and behavior (as methods).
124
What are the four "principles" of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, and Polymorphism.
125
What is "abstraction"?
Being able to work with (possibly) complex things in simple ways. Basically making complex problems easier to tackle.
126
What does API stand for?
Application Programming Interface
127
What is the purpose of an API?
It gives programmers a way to interact with a system in a simplified, consistent fashion
128
What is this in JavaScript?
this is an implicit parameter of all JavaScript functions.
129
What does it mean to say that this is an "implicit parameter"?
it means that the values change based on the context
130
When is the value of this determined in a function; call time or definition time?
during the function call
131
How can you tell what the value of this will be for a particular function or method definition?
you cannot
132
How can you tell what the value of this is for a particular function or method call?
by the object that it is being used on
133
What kind of inheritance does the JavaScript programming language use?
prototype based
134
What is a prototype in JavaScript?
an object that contains properties and (predominantly) methods that can be used by other objects.
135
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?
prototypes
136
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
__proto__ object
137
What does the new operator do?
creates a blank object, adds a property to the new object (__proto__) that links to the constructor function's prototype object, binds the newly created object instance as the this context, and returns this if the function doesn't return an object.
138
What property of JavaScript functions can store shared behavior for instances created with new?
the prototype property
139
What does the instanceof operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object
140
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 function
141
How can you set up a function to be called repeatedly without using a loop?
setInterval function
142
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0ms
143
What do setTimeout() and setInterval() return?
a timeoutID to later use with clearTimeout functions and shit
144
What is AJAX?
Ajax is a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.
145
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
146
Which object is built into the browser for making HTTP requests in JavaScript?
the XMLHttpRequest object
147
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load event
148
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
through the power of PROTOTYPES
149
What is a code block? What are some examples of a code block?
a code block is a set of instructions contained within a set of curly braces. { console.log('you are super cute') }
150
What does block scope mean?
the accessible code within that code block
151
What is the scope of a variable declared with const or let?
it can be used within the code block it was declared in
152
What is the difference between let and const?
let is mutable while const is not mutable
153
Why is it possible to .push() a new value into a const variable that points to an Array?
because the const value is holding the address of the array, not to contents inside of it.
154
How should you decide on which type of declaration to use?
if you want the value of the variable to change or not.
155
What is the syntax for writing a template literal?
using backticks instead of single or double quotes for strings
156
What is "string interpolation"?
adding expressions inside of strings.
157
What is destructuring, conceptually?
assigning properties to variables
158
What is the syntax for Object destructuring?
const { property1, property2 } = object;
159
What is the syntax for Array destructuring?
const [property1, property2 ] = array;
160
How can you tell the difference between destructuring and creating Object/Array literals?
the "assignment" of the object name is after the object or array literal.
161
What is the syntax for defining an arrow function?
parameters , arrow syntax , definition
162
When an arrow function's body is left without curly braces, what changes in its functionality?
you don't need a return statement
163
How is the value of this determined within an arrow function?
in an ES5 regular function, the value of this is determined at call time. when it is called, this is the object to the left of the method. If no object it is the window object. to sum up, the value of this in arrow functions is determined at definition time, while in ES5 functions, the value of this is defined at execution time.
164
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile( );
165
Are file operations using the fs module synchronous or asynchronous?
asynchronous
166
What are the three states a Promise can be in?
pending, fulfilled, rejected
167
How do you handle the fulfillment of a Promise?
by using the then method of the Promise object
168
How do you handle the rejection of a Promise?
by using the catch method of the Promise object
169
What is the typeof an ES6 class?
an object
170
Describe ES6 class syntax.
first start with the
171
What is "refactoring"?
changing the way how code is written, not tampering with the functionality, but making its readability easier and such.
172
What does fetch() return?
it returns a promise containing a response
173
What is the default request method used by fetch()?
GET?
174
How do you specify the request method (GET, POST, etc.) when calling fetch?
as the method property of the init object passed as a second optional argument in the fetch function
175
When does React call a component's componentDidMount method?
immediately after render
176
Name three React.Component lifecycle methods.
componentDidMount, componentUpdate, componentWillMount
177
How do you pass data to a child component?
as a prop