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
Q

Describe array literal notation.

A

square brackets [ ] with a comma between each item

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

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

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

calculate/count and stores the number of items in the 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

subtract length by one

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 repeatable series of statements to accomplish an operation

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
function name
parameters
code block

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
parentheses
arguments if required

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

parameters are placeholders for arguments (which are real data)

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

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

A

allows us to assigns the result of the function

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

allows us to assigns the result of the function and ends the function

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

keep track of js and verify output

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

What is a method?

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

methods are called using a dot notation bc they are a property of an object

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 method

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

floor method of the Math object

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

random method of the Math object

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 method to remove at an arbitrary point, pop to remove at the end, shift to remove at the beginning

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 method

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 method

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 strings are immutable, console log the original string variable or look it up on 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 (~30)

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, sometimes return is already given like a function(?)

49
Q

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

A

a lot (~30)

50
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

mdn

51
Q

Give 6 examples of comparison operators.

A

==, !=, >, =

52
Q

What data type do comparison expressions evaluate to?

A

booleans

53
Q

What is the purpose of an if statement?

A

checks conditions

54
Q

Is else required in order to use an if statement?

A

no

55
Q

Describe the syntax (structure) of an if statement.

A

if keyword,
condition within parentheses,
code to be executed if true in curly braces

56
Q

What are the three logical operators?

A

&&, ||, !

57
Q

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

A

logical operators

(condition 1) && (condition 2)

58
Q

What is the purpose of a loop?

A

repeat a function however needed

59
Q

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

A

condition determines the start/stop of the loop

60
Q

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

A

a repeat of the loop code block

61
Q

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

A

beginning of the loop and before each iteration

62
Q

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

A

once at the beginning of the loop

63
Q

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

A

before each iteration

64
Q

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

A

at the end of 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

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
Q

How do you iterate through the keys of an object?

A

for in loop

68
Q

Why are parameters useful?

A

reusability with different values

69
Q

What is JSON?

A

“JavaScript Object Notation” text-based data format used to transmit data across a network

70
Q

What are serialization and deserialization?

A

conversion of data to bytes and back in an organized way

71
Q

Why are serialization and deserialization useful?

A

data storage and transfer

72
Q

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

A

JSON.stringify

73
Q

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

A

JSON.parse

74
Q

How to you store data in localStorage?

A

localStorage.setItem takes key and value input

75
Q

How to you retrieve data from localStorage?

A

localStorage.getItem takes key from local storage

76
Q

What data type can localStorage save in the browser?

A

strings

77
Q

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

A

when window/document are about to be unloaded

78
Q

What is a method?

A

a function which is a property of an object (stored in an object)

79
Q

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

A

method definitions include a function definition whereas method calls only include object.method(parameters)

80
Q

Describe method definition syntax (structure).

A
var variable = {
 methodName: function(parameters) {
     return statement
  }
81
Q

Describe method call syntax (structure).

A

object.methodName(parameter)

82
Q

How is a method different from any other function?

A

methods can only be called within the object

83
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain data and behavior

data and behavior are paired

84
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

85
Q

What is “abstraction”?

A

being able to work with complex things in simple ways

86
Q

What does API stand for?

A

application programming interface

87
Q

What is the purpose of an API?

A

give programmers a simplified way to interact with a system

88
Q

What is ‘this’ in JavaScript?

A

an implicit parameter of all JavaScript functions, the object that the function is acting on

89
Q

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

A

this is not explicitly defined

90
Q

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

A

call time

91
Q
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);
  }
};
A

‘this’ currently refers to nothing as it has not been called yet

92
Q

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

“it’s-a-me, Mario!’

93
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

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

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

A

you don’t know

95
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

96
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal inheritance

97
Q

What is a prototype in JavaScript?

A

a template object which other objects can inherit methods and properties from

98
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

prototypal inheritance

99
Q

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

A

parent prototype in the __proto__ property

100
Q

What does the new operator do?

A

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
Q

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

A

function.prototype

102
Q

What does the instanceof operator do?

A

test if the prototype property of a constructor appears anywhere in the prototype chain of an object

103
Q

What is a “callback” function?

A

a function definition that is being passed around as a value/variable to other functions to be invoked later

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

105
Q

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

A

setInterval()

106
Q

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

A

0

107
Q

What do setTimeout() and setInterval() return?

A

interval ID as an integer

108
Q

What is AJAX?

A

programming practice of building websites that can update information without reloading the entire page

109
Q

What does the AJAX acronym stand for?

A

asynchronous javascript and xml

110
Q

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

A

XMLHttpRequest

111
Q

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

A

load

112
Q

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

A

They share the same prototype property. The event target prototype

113
Q

What is Array.prototype.filter useful for?

A

returning parts of arrays that satisfy a certain condition

114
Q

What is Array.prototype.map useful for?

A

transforming an entire array and returning an array

115
Q

What is Array.prototype.reduce useful for?

A

incrementing through an array without a for loop

116
Q

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

A

another function

117
Q
What does this code do?
const wrap = value => () => value;
A
const wrap = function(value) {
     function() {
          return value;
     }
}
118
Q

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

A

function definition

119
Q

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

A

the lexical environment, aka closure