JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Data storage for scripts to call back to

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

How do you declare a variable?

A

They are declared with
- var
- let
- const

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

Variables are initialized by including the assignment operator ‘=’
example: var example = true

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 (CANNOT be the first character of a variable name)
  • underscores(_)
  • 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

Variables names must follow the same casing when used later in a script, so the variables “fullName” and “FullName” would be detected as two different variables

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 text (a sequence of characters)

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 a piece of numerical data (for math/calculations)

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 a state of something is or is not

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

This is the assignment operator, it initializes variables and can re-assign their 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

Re-assign it with the assignment operator

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 a value explicitly assigned to not exist
Undefined is a default value set to variables that have not been assigned

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

Give five examples of JavaScript primitives.

A
  • Number
  • Boolean
  • String
  • Undefined
  • Null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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
14
Q

What is string concatenation?

A

The adding of a string to the end of another string
The result is always a string.

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

What purpose(s) does the + plus operator serve in JavaScript?

A

It tells values to combine by either concatenating or adding

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

What data type is returned by comparing two values (<, >, ===, etc)?

A

Boolean (true/false)

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

What does the += “plus-equals” operator do?

A

Addition assignment operator: adds the value of the right operand to a variable and assigns the result to the variable. Can be used to add or concatenate.

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

What are objects used for?

A

They are used to group related variables and functions

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

What are object properties?

A

Related variables/functions stored in an object become a property/method of the object

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

Describe object literal notation.

A

list out the properties and methods within curly braces and assign it to a variable

{
     hasProperty: true,
     name: 'example',
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the two ways to get or update the value of a property?

A

Dot notation and bracket notation
exampleObject.name' -dot notation
exampleObject['name'] -bracket notation

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

What are arrays used for?

A

They are used to store lists of data where the order is important or unimportant
Note: Unlike objects the key that the variables are paired to are numbers as they are indexed.

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

Describe array literal notation.

A

A list contained in two square-brackets ([ ]) with each value separated with commas

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

How are arrays different from “plain” objects?

A

The key that the variables are paired to are numbers and not properties. They are accessed with bracket-notation unless using a method.
(ex.)
console.log(exampleArray[0])

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

What is the length property of an array?

A

A property that returns the length of the array/object

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

How do you calculate the last index of an array?

A

Subtract the array length by 1
This is due to the array indexing the variables stored within using zero-based counting
(ex.)
var lastIndex = exampleArray.length - 1;

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

What is a function in JavaScript?

A

A special object that can run a code block as many times as it is called

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

Describe the parts of a function definition

A

includes the keyword function, a name for the function (optional), parameters separated by commas (if any), the code block, and the return statement (optional)
(ex.)

function exampleFunction(word) {
    var completedPhrase = 'Hello, ' + word;
    return completedPhrase;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Describe the parts of a function call

A

includes the name for the function followed by any arguments in parentheses
*(ex.) exampleFunction(arg1, arg2)

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

What are the differences between a function call and a function definition

A

A function call only includes the function name and any arguments instead of parameters
A function definition includes the keyword function and the name, as well as parameters instead of arguments, and a code block to be run

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

What is the difference between a parameter and an argument

A

A parameter is used to define a function, while an argument is a real number passed through the function.

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

6 examples of comparison operators

A
  • < less than
  • > greater than
  • <= less than or equal to
  • > = greater than or equal to
  • === strictly equal to
  • !== strictly not equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
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
35
Q

What is the purpose of an if statement?

A

To allow a specific condition to determine whether to run a code block or not

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

Is else required in order to use an if statement?

A

No, else is optional

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

Describe the syntax (structure) of an if statement

A
if (condition) {

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

What are the three logical operators?

A
  • Or (||)
  • And (&&)
  • Not (!)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

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

A

Using a logical operator

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

Why do we log things to the console?

A

Debugging purposes, if we can see what value a variable is at different sections of the code, we can figure out where things went wrong.

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

What is a method?

A

A function that is stored as a property in an object

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

How is a method different from any other function?

A

It is associated with the object it is a method of

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

How do you remove the last element from an array?

A

the .pop() method, which is implicit to arrays

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

How do you round a number down to the nearest integer?

A

Math.floor() The floor method of the Math object will take a value passed as an argument and round it down.
Note: optional parameters allow for changing the exponent and type of adjustment

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

How do you generate a random number?

A

Math.random() The random method of the Math object generates a pseudo-random float value between 0 and 1.

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

How do you delete an element from an array?

A
arrayName.pop();
arrayName.shift();
arrayName.splice();

Can be used to delete an element from an array

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

How do you append an element to an array?

A
arrayName.push();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

How do you break a string up into an array?

A
.split() - will split a string into an array based on the arguments passed through
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Do string methods change the original string? How would you check if you weren’t sure?

A

No they do not. Strings are immutable. If one wanted to check one could log the string before and after using a method to see if it changed after the method was applied.

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

Is the return value of a function/value useful in every situation?

A

No, if what we need is the original data processed and not whatever we are calculating/extracting

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

What is the purpose of a loop?

A

To re-run a code block.
One use: To run code block for each value in an array

53
Q

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

A

To specify when a loop should stop

54
Q

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

A

Each pass of the code block
“This is the nth time the loop has run”

55
Q

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

A

It runs before each code block iteration

56
Q

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

A

Before anything and only before the first iteration

57
Q

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

A

After the initialization and before each iteration of the code block

58
Q

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

A

After each iteration

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

60
Q

What does the ++ increment operator do?

A

Increases value by 1

61
Q

How do you iterate through the keys of an object?

A

A for…in loop

62
Q

What is JSON?

A

JavaScript Object Notation(JSON) is a string-based format for representing data/data structures

63
Q

What are serialization and deserialization?

A

Serialization is the conversion of a data structure into a string of bytes for the sake of storage or transporting it between systems.
Deserialization is the conversion of those strings of bytes back into a copy of the original data structure in the same state.

64
Q

Why are serialization and deserialization useful?

A

It allows data structures to be sent between differing systems and formats while still maintaining what that data structure is actually representing.

65
Q

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

A

JSON.stringify(exampleDataStructure)

66
Q

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

A

JSON.parse(exampleJSONString)

67
Q

How do you store data in localStorage?

A

`window.localStorage.setItem(‘key’, ‘value’);

68
Q

How do you retrieve data from localStorage?

A

window.localStorage.getItem('key');

69
Q

What data type can localStorage save in the browser?

A

String is the data type it can save, specifically in UTF-16

70
Q

When does the 'beforeunload' event fire on the window object?

A

It fires right before all contents on the page are about to be unloaded. (i.e closing the tab/refreshing)

71
Q

What is a method?

A

A method is a function that is a property of an object.

72
Q

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

A

A method definition includes the code that makes the function work as intended.
A method call only contains the function name and whatever arguments necessary.

73
Q

Describe method definition syntax (structure).

A

A method definition is stored as a property, then its value is the function keyword with any desired parameters then the code block.
Example:
~~~
var exampleObject = {
exampleMethod: function (parameterA, parameterB) {

 } }; ~~~
74
Q

Describe method definition syntax (structure).

A

A method definition is stored as a property, then its value is the function keyword with any desired parameters then the code block.
Example:
~~~
var exampleObject = {
exampleMethod: function () {
return ‘This is a method of the exampleObject object.’;
}
};
~~~

75
Q

Describe method call syntax (structure).

A

A method call is accessed with dot notation. Example:

exampleObject.exampleSum(1 , 2);
76
Q

How is a method different from any other function?

A

It exists inside an object. It can only be called with the object.

77
Q

What is the defining characteristic of Object-Oriented Programming?

A

It uses objects which store both data and behavior.

78
Q

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

79
Q

What is “abstraction”?

A

Dealing with complex problems with simple means/simplifying an otherwise complex process into easy steps.

80
Q

What does API stand for?

A

Application Programming Interface

81
Q

What is the purpose of an API?

A

It gives programmers a way to interact with a system in a simplified way.

82
Q

What is this in JavaScript?

A

this is an implicit parameter

83
Q

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

A

It means that even if it is not explicitly stated it implicitly exists.

84
Q

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

A

Call time

85
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 refers to nothing.

86
Q

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

A

It's -a-me, Mario! will be the result. This is because of the this keyword being called in the greet method referencing the character.firstName property.

87
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! will be the result. This is because the this keyword cannot reference the character object since it is being assigned to a new variable, the method is not being called off the object. This is referencing the window object.

88
Q

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

A

You can’t since the method/function isn’t being called.

89
Q

How can you tell what the value of this is for a particular function or method call?

A

Object to the left of the dot of the method call, if none is present it defaults to the window object.

90
Q

What kind of inheritance does the JavaScript programming language use?

A

It uses prototype-based (prototypal) inheritance.

91
Q

What is a prototype in JavaScript?

A

It is an object which stores general functionality that can be shared with many different objects that are patterned after it/similar to it.

92
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

Each of those methods are stored on the prototype object of that kind of data type.

93
Q

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

A

Within the prototype object of that data type.

94
Q

What does the new operator do?

A

It creates a new instance of an object with the same [[Prototype]] as the specified constructor, executes the function with whatever arguments have been passed through to allow this to have a context of the new instance of the object, and then returns the object from the constructor function.

95
Q

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

A

The prototype property.

96
Q

What does the instanceof operator do?

A

It checks if an object is an instance of a constructor function ( does the object use the same prototype )

97
Q

What is a “callback” function?

A

A function that is passed as an argument of another function.

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

99
Q

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

A

setInterval()

100
Q

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

A

0

101
Q

What do setTimeout() and setInterval() return?

A

They return unique IDs that can be used inside of clearTimeout() or clearInterval()

102
Q

What is AJAX?

A

A group of technologies used to create asynchronous web applications

103
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

104
Q

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

A

XMLHttpRequest

105
Q

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

A

load

106
Q

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

A

Both are objects.

107
Q

What is Node.js?

A

A set of JavaScript libraries that allows it to be used outside of the browser.

108
Q

What can Node.js be used for?

A

It is used for backend such as network clients and servers.

109
Q

What is a REPL?

A

It stands for Read-eval-print-loop, it basically takes what is input and evaluates what was input then prints out the result.

110
Q

When was Node.js created?

A

2009 by Ryan Dahl

111
Q

What is a computer process?

A

A collected list of instructions being executed by the computer. It can be viewed as the environment controlled by the OS in which a program is run, with memory allocated and CPU time allocated.

112
Q

What is the process object in a Node.js program?

A

A global object representing the node process being run.

113
Q

How do you access the process object in a Node.js program?

A

One can directly access the process object within their REPL or actual files

114
Q

What is the data type of process.argv in Node.js?

A

It is an array

115
Q

What is a JavaScript module?

A

A file that has functions/variables that can be exported to be processed in other files

116
Q

What values are passed into a Node.js module’s local scope?

A

exports, require, module, __filename, __dirname

117
Q

What is the JavaScript Event Loop?

A

It is a mechanism in which asynchronous tasks are added to a queue and is executed if the stack is empty. (Stack is like the “job list” for the synchronous tasks)

118
Q

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

A

Blocking: Each step must be finished in the order the code is called
Non-blocking: The order in which steps are executed can be deferred/changed

119
Q

What method is available in the Node.js fs module for writing data to a file?

A

writeFile()

120
Q

Are file operations using the fs module synchronous or asynchronous?

A

Asynchronous

121
Q

What are the three states a Promise can be in?

A
  • pending (waiting for an async task to complete)
  • fulfilled (successfully completed task)
  • rejected (failed to complete task)
122
Q

How do you handle the fulfillment of a Promise?

A

with .then()

123
Q

How do you handle the rejection of a Promise?

A

with .catch()

124
Q

What is Array.prototype.filter useful for?

A

It’s useful for filtering an array to get the values that obey certain conditions. (NOTE: returns a copy instead of changing original)

125
Q

What is Array.prototype.map useful for?

A

It’s useful for modifying every value in the same manner and returning a copy.

126
Q

What is Array.prototype.reduce useful for?

A

Combining related data (ie. account balances)

127
Q

What does fetch() return?

A

It returns a promise that resolves to the Response object representing the response to our request from the specified resource.

128
Q

What is the default request method used by fetch()?

A

GET

129
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

One would specify it in the method property of the optional options parameter.