JavaScript Flashcards

1
Q

What is the purpose of variables?

A

stores values and updates values, also gives value permanence (don’t have to keep declaring variable value)

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

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

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

can start with: $, _, letters

can contain: $, _, letter, numbers

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

javascript distinguishes between lower and upper cased letters

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

pass around characters not to be interpreted as code (text content)

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

math

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

store true/false values, used for decision making (this or that)

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

putting a value into something

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

reassign variable value

variablename = newvalue

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

both return/represent nothing/emptiness,
null: intentional nothingness (null is an assigned value), typically temporary space holder to be filled later

undefined typically unused by developers - usually a return from the console signifying the value has been deleted or was not assigned a 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

gives a 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, number, boolean, undefined, null

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

adds strings/numbers together to one larger string

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

arithmetic operation 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 and assigns the sum 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

area to store related properties

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

What are object properties?

A

variables within objects (/associated with objects)

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

Describe object literal notation.

A

curly braces + properties and values + object name

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

bracket notation allows the text within to be interpreted by javascript (eg you can use variable names)

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
Describe array literal notation.
square brackets [ ] with a comma between each item
26
How are arrays different from "plain" objects?
arrays are ordered, items are indexed (basically an object w keywords as consecutive numbers), arrays will repair themselves if items are deleted, arrays have a set length
27
What number represents the first index of an array?
0
28
What is the length property of an array?
calculate/count and stores the number of items in the array
29
How do you calculate the last index of an array?
subtract length by one
30
What is a function in JavaScript?
a repeatable series of statements to accomplish an operation
31
Describe the parts of a function definition.
function keyword function name parameters code block
32
Describe the parts of a function call.
function name parentheses arguments if required
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
``` function call is much shorter since it doesn't have to define the function in curly braces function calls contain arguments in ' ' while definitions contain parameters ```
34
What is the difference between a parameter and an argument?
parameters are placeholders for arguments (which are real data)
35
What two effects does a return statement have on the behavior of a function?
allows us to assigns the result of the function
36
What two effects does a return statement have on the behavior of a function?
allows us to assigns the result of the function and ends the function
37
Why do we log things to the console?
keep track of js and verify output
38
What is a method?
function that is a property of an object
39
How is a method different from any other function?
methods are called using a dot notation bc they are a property of an object
40
How do you remove the last element from an array?
pop method
41
How do you round a number down to the nearest integer?
floor method of the Math object
42
How do you generate a random number?
random method of the Math object
43
How do you delete an element from an array?
splice method to remove at an arbitrary point, pop to remove at the end, shift to remove at the beginning
44
How do you append an element to an array?
push method
45
How do you break a string up into an array?
split method
46
Do string methods change the original string? How would you check if you weren't sure?
no strings are immutable, console log the original string variable or look it up on mdn
47
Roughly how many string methods are there according to the MDN Web docs?
a lot (~30)
48
Is the return value of a function or method useful in every situation?
no, sometimes return is already given like a function(?)
49
Roughly how many array methods are there according to the MDN Web docs?
a lot (~30)
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?
booleans
53
What is the purpose of an if statement?
checks conditions
54
Is else required in order to use an if statement?
no
55
Describe the syntax (structure) of an if statement.
if keyword, condition within parentheses, code to be executed if true in curly braces
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
logical operators | (condition 1) && (condition 2)
58
What is the purpose of a loop?
repeat a function however needed
59
What is the purpose of a condition expression in a loop?
condition determines the start/stop of the loop
60
What does "iteration" mean in the context of loops?
a repeat of the loop code block
61
When does the condition expression of a while loop get evaluated?
beginning of the loop and before each iteration
62
When does the initialization expression for a for loop get evaluated?
once at the beginning of the loop
63
When does the condition expression for a while loop get evaluated?
before each iteration
64
When does the final expression of a for loop get evaluated?
at the end of 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?
increments the variable and reassigns incremented value to the variable and the end of the expression if placed at the end (i++), assigns at the before the end if placed before (++i)
67
How do you iterate through the keys of an object?
for in loop
68
Why are parameters useful?
reusability with different values
69
What is JSON?
"JavaScript Object Notation" text-based data format used to transmit data across a network
70
What are serialization and deserialization?
conversion of data to bytes and back in an organized way
71
Why are serialization and deserialization useful?
data storage and transfer
72
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify
73
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
74
How to you store data in localStorage?
localStorage.setItem takes key and value input
75
How to you retrieve data from localStorage?
localStorage.getItem takes key from local storage
76
What data type can localStorage save in the browser?
strings
77
When does the 'beforeunload' event fire on the window object?
when window/document are about to be unloaded
78
What is a method?
a function which is a property of an object (stored in an object)
79
How can you tell the difference between a method definition and a method call?
method definitions include a function definition whereas method calls only include object.method(parameters)
80
Describe method definition syntax (structure).
``` var variable = { methodName: function(parameters) { return statement } ```
81
Describe method call syntax (structure).
object.methodName(parameter)
82
How is a method different from any other function?
methods can only be called within the object
83
What is the defining characteristic of Object-Oriented Programming?
objects can contain data and behavior | data and behavior are paired
84
What are the four "principles" of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism
85
What is "abstraction"?
being able to work with complex things in simple ways
86
What does API stand for?
application programming interface
87
What is the purpose of an API?
give programmers a simplified way to interact with a system
88
What is 'this' in JavaScript?
an implicit parameter of all JavaScript functions, the object that the function is acting on
89
What does it mean to say that this is an "implicit parameter"
this is not explicitly defined
90
When is the value of this determined in a function; call time or definition time?
call time
91
``` What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } }; ```
'this' currently refers to nothing as it has not been called yet
92
Given the above character object, what is the result of the following code snippet? Why? character.greet();
"it's-a-me, Mario!'
93
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
"it's-a-me, undefined!' when assigning value to var hello, value of character.greet is now free floating and no longer attached to the object, but instead attached to the window object where there is no firstName property thus 'this' is being invoked on window and cannot access firstName
94
How can you tell what the value of this will be for a particular function or method definition?
you don't know
95
How can you tell what the value of this is for a particular function or method call?
the object to the left of the dot
96
What kind of inheritance does the JavaScript programming language use?
prototypal inheritance
97
What is a prototype in JavaScript?
a template object which other objects can inherit methods and properties from
98
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?
prototypal inheritance
99
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
parent prototype in the __proto__ property
100
What does the new operator do?
creates a blank javascript object, adds proto property, links constructor prototype, 'this' now refers to new object, returns 'this' if function doesnt return an object
101
What property of JavaScript functions can store shared behavior for instances created with new?
function.prototype
102
What does the instanceof operator do?
test if the prototype property of a constructor appears anywhere in the prototype chain of an object
103
What is a "callback" function?
a function definition that is being passed around as a value/variable to other functions to be invoked later
104
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()
105
How can you set up a function to be called repeatedly without using a loop?
setInterval()
106
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
107
What do setTimeout() and setInterval() return?
interval ID as an integer
108
What is AJAX?
programming practice of building websites that can update information without reloading the entire page
109
What does the AJAX acronym stand for?
asynchronous javascript and xml
110
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
111
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
112
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They share the same prototype property. The event target prototype
113
What is Array.prototype.filter useful for?
returning parts of arrays that satisfy a certain condition
114
What is Array.prototype.map useful for?
transforming an entire array and returning an array
115
What is Array.prototype.reduce useful for?
incrementing through an array without a for loop
116
What must the return value of myFunction be if the following expression is possible? myFunction()();
another function
117
``` What does this code do? const wrap = value => () => value; ```
``` const wrap = function(value) { function() { return value; } } ```
118
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
function definition
119
What allows JavaScript functions to "remember" values from their surroundings?
the lexical environment, aka closure