JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store, represent, and access data via an easily accessible name called an identifier.

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, or in ES6: let and const keywords.

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

Using the assignment operator = followed by the value, followed by a semi-colon.

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, dollar sign, or an underscore.

Cannot begin with a number.

Notes: Using the underscore is not very common in JavaScript, but a convention among professional programmers is to use it as an alias for “private (hidden)” variables.

Using the $ is not too common, but professional programmers often use it as an alias for the main function in a JavaScript library or using them for variables holding DOM elements. In jQuery, for instance, the main function $ is used to select HTML elements. In jQuery $(“p”); means “select all p elements”.

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

That changing the case of a letter in a declared variable name will not access the value. The memory address for a variable is assigned to the identifier using the case the declaration was made it. Guidelines state to use camelCase.

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

For storing and manipulating a sequence of characters or text

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 and manipulate numerical values and to do math, more precisely 64 bit floating point numbers (up to 15 digits and 17 decimals), positive and negative infinity, and NaN.

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 find out if an expression or a variable is true or false or when you need a data type that can only have two values, like on and off. Used for comparisons and for decision-making in a program (conditionals).

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’s an assignment operator, it assigns 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

Using the assignment operator, math functions or other methods, or changing property values

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

Undefined is the absence of data, no value is assigned, is falsy.
Null is the intentional absence of data, treated as a falsy value. Usually a placeholder for data that later gets created or added.

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 describes the value being logged, it can help with debugging by adding clarity to what you’re looking at and what’s happing in your script.

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, and null.
- extra -
bigint, symbol,

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

It’s the operation of joining strings together, which can be done with the addition operator or a template literal – or you can cheat with just using a comma between strings, lol.

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, addition, and the unary plus operator converts its operand to Number type.

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

It adds the value to the right of the addition assignment operator to the variable and then assigns the result of the expression to that 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 a group of key/value pairs and methods as a single entity, or model, as Duckett describes it.

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

What are object properties?

A

Variables that store some related data about the object, often referred to as key/value pairs.

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

Describe object literal notation.

A

Variable declaration or identifier for the for the object, then wrapped in curly braces, property or keys and values separated by a colon, multiple key/value pairs are separated by commas.

ex: var objectName = {
property: value,
property: value
}

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

Using the delete keyword followed by object.property (or object[‘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 or 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

To store lists, usually ordered lists.

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

Describe array literal notation.

A

Variable declaration to store the array in, then wrapped in square brackets, a list of values separated by commas.

Ex: var arrayName = [item1, item2, item3];

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

They do not hold custom keys for which the values are paired, rather they are numerically indexed.

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

The number of items in an 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

array.length - 1

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

What is a function in JavaScript?

A

It’s a set of statements that performs a task, like a procedure. Referred to as a power tool, per the reading.

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

1) A function is defined with the function keyword,
2) An optional function name,
3) then 0 or more parameters wrapped in parentheses, separated by commas
4) Then, the function’s code block wrapped in curly brackets,
5) Which may contain an optional return statement.

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

1) function name
2) optional comma-separated argument list wrapped in parentheses
3) followed by a semi-colon.
W3 called this ‘calling from code’.

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

A function definition includes the function keyword (in ES5), optional parameters, and a code block defining what the function does.

A function call uses the defined function and includes the arguments you want to pass into the function.

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 values that can be passed into a function and are listed inside parentheses in the function declaration. They are usually a variable with a descriptive identifier. They are local variables scoped to a function block.

Arguments are the actual values you’re passing into the function and are wrapped by parentheses when you invoke the function.

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

Why are function parameters useful?

A

They are variables accessible by the function code block and tell us what to pass into a function, and often (not always), the number of arguments to pass in.

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

1) Causes the function to produce a value we can use in our program.
2) Exits the code block and prevents any more code past the return statement from being run.

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

To assist with debugging and to add clarity to what you’re looking at and what’s happing in your script.

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

What is a method?

A

It’s a function that’s stored as a property of an object.
There are 2 kinds – instance methods and static methods.

Instance methods are built-in functions that are typically used on an instance of an object, typically an object you would create, so the method is called on the instance of the created object.

Static methods are directly accessible from an object’s constructor and are referenced by the object name and can be invoked without creating an instance of an object. Ex: Math object methods, and Array object methods.

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 directly associated with 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

ex: array.pop();

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

Math.floor(); method

ex: Math.floor(number)

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

Math.random(); (kind of)

This produced a pseudo-random number from 0 up to, but not including 1.

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

1) You can use the .splice(); method on a specific index and for a number of indexes.
2) You can use the .pop(); method to remove one from the end.
3) You can use the .shift(); method to remove one from the front of an array.
4) You can reassign the length property to delete a number of indexes at the end of an array, but this is very dangerous and should probably be avoided.

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

ex: array.push(‘new-item’);

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 and pass in arguments that define the separator, and a limit of splits (optional).

(There is also the Array.from(); method if you want to split each character as a different index.)

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. You can check by logging the variable to which the original string was assigned to the console.

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

Around 3 static, and 33 instance methods.

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, because sometimes the function output is not germane to the task we’re trying to accomplish. For instance, in this exercise, the unshift and push methods return the new length of the array and we may not always care about the new length, but rather care about the index values of the array.

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

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

A

Around 3 static, and 35 instance methods.

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

Give 6 examples of comparison operators.

A
>=   
>     
<= 
<     
===    
!==
==
!=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

What data type do comparison expressions evaluate to?

A

Booleans

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

What is the purpose of an if statement?

A

It checks conditions as true or false, and should the condition(s) be met, the following code block executes.

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

Is else required in order to use an if statement?

A

No, if you are looking for a condition to evaluate to true, the only other else is false, and therefore is not needed.

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

Describe the syntax (structure) of an if statement.

A

1) If keyword,
2) Followed by a condition wrapped in parentheses,
3) Followed by a code block to execute if the condition is met wrapped in curly braces.

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

What are the three logical operators?

A

1) && (AND)
2) || (OR)
3) ! (NOT)

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

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

A

Using the logical AND or OR operators.

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

What is the purpose of a loop?

A

To repeatedly check conditions and perform the same set of steps (run a code block or statement) until the condition evaluates false.

NOTE: A do…while loop will always run once, even if the condition evaluates to false.

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

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

A

To tell the loop when to run and when to stop.

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

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

A

It’s referring to the repetition each time the code is run, each loop.

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

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

A

It’s evaluated before executing the statement, or the code block, every loop.

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

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

A

It’s evaluated first, before anything else, and only gets evaluated once.

Typically used to initialize a counter variable.

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

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

A

After the initialization expression on the first loop, and before each loop iteration and

If omitted, the condition always evaluates to true.

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

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

A

At the end of each loop iteration, before the next condition check. Used to update or increment the counter variable.

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

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

What does the ++ increment operator do?

A

Increments the counter variable by 1, it’s the same +=1

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

How do you iterate through the keys of an object?

A

Using a for…in loop.

Arrays are for…of loops.

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

What is a “model”?

A

It is a representation or recreation of something, in this case html recreated as nodes and objects

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

Which “document” is being referred to in the phrase Document Object Model?

A

The HTML document.

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

What is the word “object” referring to in the phrase Document Object Model?

A

JavaScript Object

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

What is a DOM Tree?

A

It is a model of a webpage, and is constructed out of four main types of nodes, the document node, element nodes, attribute nodes, and text nodes.

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

Give two examples of document methods that retrieve a single element from the DOM.

A

.querySelector()

.getElementByID()

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

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

.getElementsByClassName()
-extra-
.getElementsByTagName()
.querySelectorAll()

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

Why might you want to assign the return value of a DOM query to a variable?

A

To access and manipulate the return value, especially if you need it more than once

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

What console method allows you to inspect the properties of a DOM element object?

A

Console.dir - displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.

In other words, console.dir() is the way to see all the properties of a specified JavaScript object in console by which the developer can easily get the properties of the object.

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

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

In order for the browser to parse the HTML first, then the script can access the HTML elements.
Any time you want to access the DOM and use JavaScript to manipulate it, we must add the script tag at the bottom of the body.

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

What does document.querySelector() take as its argument and what does it return?

A

It takes a CSS selector (in string form) as it’s argument.
It returns the first Element within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned.

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

What does document.querySelectorAll() take as its argument and what does it return?

A

It takes a selector (in string form) as the argument.

It returns a NodeList representing a list of the document’s elements that match the specified group of selectors.

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

What is the purpose of events and event handling?

A

Events are fired to notify code of “interesting changes”, and have your script do something in response to the event. Handling events allows you to execute specified code on a specified element at the time of the event.

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

Are all possible parameters required to use a JavaScript method or function?

A

No, not always. They can be optional.

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

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

.addEventListener()

82
Q

What is a callback function?

A

A function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

83
Q

What object is passed into an event listener callback when the event fires?

A

The event object.

84
Q

What is the event.target? If you weren’t sure, how would you check?

A

It is the element that the event is bound to. You can check by console logging the target property of the event object.

In general targets are objects that can receive events and may have listeners for them. Element, and its children, as well as Document and Window, are the most common event targets.

85
Q

Where could you get more information about the event.target?

A

In the console, in the target property of the event object. Target is an object that has it’s own set of properties.

86
Q
What is the difference between these two snippets of code?
element.addEventListener(
'click', handleClick
)
element.addEventListener(
'click', handleClick()
)
A

The second is an IIFE – it is immediately invoked without parameters, so for this example, as soon as the JS is parsed by the browser, the function tries to run but the event is then undefined.

87
Q

What is the className property of element objects?

A

The className property of the Element interface gets and sets the value of the class attribute of the specified element.

88
Q

How do you update the CSS class attribute of an element using JavaScript?

A

By using the .className property of the desired element, and reassigning the value to a different class string,

89
Q

What is the textContent property of element objects?

A

It represents the text content of the node and its descendants, and allows you to collect or update the just the text that’s in the containing elements (and it’s children).

90
Q

How do you update the text within an element using JavaScript?

A

By using the .texContent property of the desired element and reassigning the value to a different string.

91
Q

Is the event parameter of an event listener callback always useful?

A

No, it’s not always needed, and we might not reference it.

92
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

More difficult due to the amount of times we have to reference the number of clicks and place conditions on the quantity.

93
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

To easily access them a number of times and to add clarity to the code.

94
Q

What event is fired when a user places their cursor in a form control?

A

Focus event

95
Q

What event is fired when a user’s cursor leaves a form control?

A

Blur event

96
Q

What event is fired as a user changes the value of a form control?

A

Input event

97
Q

What event is fired when a user clicks the “submit” button within a ?

A

Submit event

98
Q

What does the event.preventDefault() method do?

A

Any default action normally triggered as a result of the event will not occur.

99
Q

What does submitting a form without event.preventDefault() do?

A

It sends the form, and reloads the page

100
Q

What property of a form element object contains all of the form’s controls.

A

.elements property

101
Q

What property of a form control object gets and sets its value?

A

Value property is the property used by inputs to get and set values.

102
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

That nothing works in the end and you don’t know where the potential error occurred. It’s also the same risk as moving code around in your page.

103
Q

What is an advantage of having your console open when writing a JavaScript program?

A

To see what’s happening in the program, when things are or aren’t firing, and to test things in the console to make sure they are doing what you expect.

104
Q

Does the document.createElement() method insert a new element into the page?

A

No, appendChild() method inserts the element into the page.

105
Q

How do you add an element as a child to another element?

A

You call the appendChild() method on the parent object with the child as the method’s argument.

106
Q

What do you pass as the arguments to the element.setAttribute() method?

A

The attribute name and the attribute value, separated by a comma.

107
Q

What steps do you need to take in order to insert a new element into the page?

A

You need to first create the element with the createElement() method, then you can optionally set that element’s attribute(s) using the setAttribute() method, then you can optionally create the text content for that element using the .createTextNode() method. Then you need to append the element to it’s parent element in the DOM by using the appendChild() method.

108
Q

What is the textContent property of an element object for?

A

To get or set the text content of the element.

109
Q

Name two ways to set the class attribute of a DOM element.

A

1) The .className() property of the Element interface gets and sets the value of the class attribute of the specified element.
2) The .setAttribute() method sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value.

110
Q

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

1) Saves time manually entering all the code for the same procedure with different data, piece by piece, instead, you can reuse the function.
2) Easier to read what’s happening in the code.

111
Q

What is the event.target?

A

The object that the event is bound to, or dispatched from.

112
Q

Why is it possible to listen for events on one element that actually happen to its descendent elements?

A

Because bubbling allows us to move outward from most specific (child) to less specific (parent).

113
Q

What is ‘this’ in JavaScript?

A

It’s an implicit parameter, meaning that it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var.

If there is no value to the left of the dot when the function is called, then by default, this will be the global window object.

114
Q

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

A

The parameter is available in a function’s code block even though it was never included in the function’s parameter list or declared with var. It doesn’t need to be explicitly stated.

115
Q

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

A

Call time.

116
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 the character object.

117
Q
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};

Given the above character object, what is the result of the following code snippet? Why?

character.greet();

A

“It’s-a-me, Mario!” because this is referencing the object’s property firstName which has a value of ‘Mario’.

118
Q
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';

Given the above character object, what is the result of the following code snippet? Why?

var hello = character.greet;
hello();
A

this.firstName will return undefined, because it’s in the lexical scope of the window.

119
Q

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

A

If you cannot see the function being called, then you do not know what the value of this will be.

120
Q

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

A
  • The value of this can be recognized as “the object to the left of the dot” when the function is called (as a method).
  • If there is no value to the left of the dot when the function is called, then by default, this will be the global window object.
121
Q

What is a method?

A

A method is a function which is a property of an object.
NOTE: There are two kind of methods: Instance Methods which are built-in tasks performed by an object instance, or Static Methods which are tasks that are called directly on an object constructor.

122
Q

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

A

A method is defined as an anonymous function inside an object literal as the value to a key, where a method call passes in arguments and is called with dot or bracket notation on the object.

123
Q

Describe method definition syntax (structure).

A

An object literal is assigned to a variable, and within the object, an anonymous function with any number of parameters is assigned as a property’s value.

124
Q

Describe method call syntax (structure).

A

The object name, dot (or bracket), property name which has the method as its value, followed by arguments wrapped in parentheses.

125
Q

How is a method different from any other function?

A

A method is a property of an object with a function as it’s value, and a function can live on it’s own. A method must be called with the name of it’s object, and a function can be called directly by its name.

126
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects can contain both data (as properties) and behavior (as methods).

127
Q

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

A
  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism
128
Q

What is “abstraction”?

A

The concept of being able to work with (possibly) complex things in simple ways, an overall generalization of a process or procedure.

129
Q

What does API stand for?

A

Application programming interface

130
Q

What is the purpose of an API?

A

Creates a connection between computers and/or between computer programs, allows programmers a way to interact with a system in a simplified, consistent fashion.

131
Q

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

A

When the window, the document, and its resources are about to unload – when you reload the page.

132
Q

What data type can localStorage save in the browser?

A

A storage object

133
Q

How do you retrieve data from localStorage?

A

Calling the .getItem() method on the keyname of the item.

134
Q

How do you store data in localStorage?

A

Calling the .setItem() method on the data (keyName, keyValue).

135
Q

What is JSON?

A

JSON, or JavaScript Object Notation, is a text-based data format following JavaScript object syntax for serializing objects, arrays, numbers, strings, Booleans, and null. It is commonly used for transmitting data in web applications and computer systems

136
Q

What are serialization and deserialization?

A

Serialization: converting a native object to a string so it can be transmitted across the network.
Deserialization: Converting a string to a native object

137
Q

Why are serialization and deserialization useful?

A

Because they allow for an object or data structure to be translated into a format that can be sent over a network or storage and then be converted back to the object or data structure.

138
Q

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

A

Calling the JSON.stringify() method on the object you want to serialize.

139
Q

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

A

Calling the JSON.parse() method on the string you want to deserialize.

140
Q

What is a “callback” function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

141
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

Use the setTimeout() function with a delay, or the setInterval() function with a delay.

142
Q

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

A

Use the setInterval() function.

143
Q

What is a code block? What are some examples of a code block?

A

Code blocks are denoted by curly braces {}, (when not being used for an object literal) for example, the code after a for or while loop, an if, else statement, etc.

144
Q

What does block scope mean?

A

It means that if a variable is declared in block scope that the declared value is only accessible within that code block and cannot be accessed outside of the code block, that variable is not attached to the global object as a property.

145
Q

What is the scope of a variable declared with const or let?

A

Block scope

146
Q

What is the difference between let and const?

A

A variable declared with let can be reassigned different values. However, a variable declared with const is immutable, meaning you cannot reassign the value, it creates a read-only reference to a value.

147
Q

Why is it possible to .push() a new value into a const variable that points to an Array?

A

Because the value of the variable is a reference to the array, and the array that’s referenced isn’t changing, only its contents.

148
Q

How should you decide on which type of declaration to use, between let and const?

A

Base it on whether or not you are going to modify the variable, if you are going to modify the variable, then use let, if you are never going to modify the value of the variable, use const.

149
Q

What is destructuring, conceptually?

A

Destructuring provides an alternative way to assign properties of an object to variables.

150
Q

What is the syntax for Object destructuring?

A

let { property1: variable1, property2: variable2 } = object;

If the variables have the same names as the properties of the object, you can make the code more concise as follows:
let { firstName, lastName } = person;

151
Q

What is the syntax for Array destructuring?

A

const [ firstIndex, secondIndex ] = array;
Could also use rest operator for reaming indexes:
const [ firstIndex, secondIndex, …indexes ] = array;

152
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

When you create an object or array, you assign the array or object literal to the identifier, in destructuring, you assign the objects reference identifier to the property variables.

The syntax is essentially flipped on either side of the assignment operator.

153
Q

What is the syntax for defining an arrow function?

A
const funcName = a => a * a
-or-
const complexFuncName = (a, b, c) {
~return more complex code here~ 
}

Let or const, the function name (optional) the assignment operator, the parameters wrapped in parentheses if more than one, also optional (empty parentheses if none) and the arrow (equals and greater than symbol), then if your code block is a simple expression, you can omit the curly braces and return statemtn, but if it’s a statement, wrap the code in curly braces and use the return statement.

154
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

Whatever follows the arrow is immediately returned – with curly braces, we need a return statement.

155
Q

How is the value of this determined within an arrow function?

A

It is dependent upon it’s lexical scope.
It doesn’t have it’s binding to this.
An arrow function captures the this value of the enclosing context instead of creating its own this context.
In an arrow function this is determined at definition time. In a regular function, this is determined at call time, the obj attached to the method.
If ‘this’ is determined properly, then any reference to this using an arrow function inside the parent function, it’ll take the previous reference.
Regular functions will redefine this, arrow function do not. Arrow functions will take on this when it’s called.

156
Q

What is Node.js?

A

An asynchronous event-driven JavaScript runtime program that allows JavaScript to be run outside of a web browser.
It is powered by V8 engine; the same JavaScript engine in the Google Chrome browser. It is free, open-source software and its source code is available on GitHub.

157
Q

What can Node.js be used for?

A

Node.js is designed to build scalable network applications, it is commonly used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.

158
Q

What is a REPL?

A

Read–eval–print loop.
AKA an interactive toplevel or language shell, - a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise.

Ex: the console, a terminal, etc.

159
Q

When was Node.js created?

A

The initial release was in 2009, authored by Ryan Dahl.

160
Q

What back-end languages have you heard of?

A

Ruby, Python, .Net or C#, Java, PHP, Node, Rust, Go

161
Q

What is a CLI?

A

A command-line interface (CLI) processes commands to a computer program in the form of lines of text, like git, or a terminal.

162
Q

What is a GUI?

A

A graphical user interface. They allow users to interact with electronic devices through graphical icons rather than text-based user interfaces. Examples of GUIs include VS Code, the browser, our operating system, Microsoft Word, or any application we use on our computers.

163
Q
Give at least one use case for each of the commands listed below: 
o	man
o	cat 
o	ls 
o	pwd 
o	echo  
o	touch 
o	mkdir  
o	mv 
o	rm 
o	cp
A

o man – to look up what a command does and how to use it.
o cat – print the text content of a file to quickly see what the contents are, or to add the contents of two files together.
o ls – to quickly list what’s in a directory (ls stands for list segments)
o pwd – to print the name of the current working directory – see where you currently are.
o echo – to display a line of text – could use it to send string(s) to a file.
o touch – to create or update files.
o mkdir – to make a directory without needing to do it in the file explorer.
o Mv – to rename a directory.
o Rm – to delete a file or directory without needing to do it in the file explorer.
o Cp – copy the contents of a file to use them in another file.

164
Q

What are the three virtues of a great programmer?

A

Hubris, impatience, and laziness.

165
Q

What is the syntax for writing a template literal?

A

In ES6, you create a template literal by wrapping your text in backticks () and to instruct JavaScript to substitute a variable and expression, you wrap the variable and expression in curly braces following a dollar sign ($). Ex: Hi, my name is ${nameVaraibale}.’

166
Q

What is “string interpolation”?

A

The ability to substitute part of the string for the values of variables or expressions.

167
Q

What is deadlocking?

A

A deadlock occurs when 2 processes are competing for exclusive access to a resource but is unable to obtain exclusive access to it because the other process is preventing it. This results in a standoff where neither process can proceed. The only way out of a deadlock is for one of the processes to be terminated.

168
Q

What is a computer process?

A

a process is the instance of a computer program in execution, that is being executed by one or many threads or set of sequential instructions. (In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system.).

It contains the program code and its activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently.

While a computer program is a passive collection of instructions typically stored in a file on disk, a process is the execution of those instructions after being loaded from the disk into memory.

169
Q

Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?

A

On PC - ~300 including windows processes.

On Mac - ~500

170
Q

Why should a full stack Web developer know that computer processes exist?

A

Because full stack web development is based on making multiple processes work together to form one application, front-end processes, server processes, and database processes using APIs.

171
Q

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

A

The process object is a global object that provides information about, and control over, the current Node.js process.

172
Q

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

A

Using the process variable.

More precisely, by logging the process object in the js file and in the terminal, in the correct directory, using the node command followed by the file name.

173
Q

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

A

It is an array (object)

174
Q

What is a JavaScript module?

A

In JavaScript, a “module” is a single .js file, which contains code for a specific task. Breaking up code into multiple files helps things stay organized and isolated.

175
Q

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

A
The parameters in the function wrapper: 
 (function(exports, require, module, \_\_filename, \_\_dirname) {
// Module code actually lives in here
});

The five parameters: exports, require, module, __filename, __dirname

176
Q

Give examples of truly global variables in a Node.js program.

A

Process, Buffer, and global

177
Q

What is the purpose of module.exports in a Node.js module?

A

To access the functionality or code from another file or module with a simplified variable while potentially being able to isolate other non-relevant modules. It instructs the program on which module(s) to utilize when.

178
Q

How do you import functionality into a Node.js module from another Node.js module?

A

By first assigning the exported module functionality to the exports property, and then on the importing module, call the require method of the module object with the exported file path as a string and assign that to a variable which can then be utilized to import the exported functionality.

179
Q

What is a client?

A

A client is a computer, server, program, etc., that initiates communication with servers by making content or service requests via HTTP messages. A client usually doesn’t share any of its resources.

180
Q

What is a server?

A

An HTTP server waits for incoming client requests and serves or responds to the client based on the requested data. A server shares its resources with clients. Servers are classified by the services they provide, e.g. file server, or web server.

181
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

The GET Method.

182
Q

What is on the first line of an HTTP request message?

A

The startline, which contains the HTTP Method, the request target (URL, absolute path, etc), and the HTTP version.

183
Q

What is on the first line of an HTTP response message?

A

The status line which contains the HTTP version, the status code (like 200 or 404), and the status text (like OK, or Not Found).

184
Q

What are HTTP headers?

A

An optional second part of a request, specifying the request, or describing the body included in the message, each formatted as a case-insensitive string followed by a colon (‘:’) and a value whose structure depends upon the header.
You can also add custom headers in any key value pair. One common would be authorization token.

There are three categories of headers:

1) representational, like Content-Type,
2) request, like user-agent and
3) general, like via or connection.

185
Q

Is a body required for a valid HTTP message?

A

No the body is optional, but some do contain bodies, such as requests that send data to the server in order to update it: as often the case with POST requests (containing HTML form data).

186
Q

What are the response code categories you can get from an HTTP request?

A

Informational - 100-199
Successful responses – 200-299
Redirection messages – 300-399
Client error messages – client successfully made it to the server, but the request has some errors. 400-499
Server error messages – 500-599, client successfully communicated, but there is something wrong with the server.

187
Q

How are ES Modules different from CommonJS modules?

A

They use the export and import keywords, and have 2 different types of exports, rather than using the require function and modules.export object

188
Q

What kind of modules can Webpack support?

A

CommonJS, ES6, AMD, and others. There are many.

189
Q

What is “syntactic sugar”?

A

It is syntax within a programming language that is designed to make things easier to read or to express. It makes the language “sweeter” for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

Usually new syntax that improves the ways we code things to make things easier

190
Q

What is the typeof an ES6 class?

A

A Function

191
Q

Describe ES6 class syntax

A

Class keyword then, wrapped in curly braces, an optional constructor and parameters for pre-set properties, followed by the property assignments in curly braces, followed by any method names with parentheses and a code block

192
Q

What is “refactoring”?

A

Code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior. Refactoring is intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functionality.

193
Q

What is an ES6 JS class?

A

A JavaScript class is a blueprint for creating objects. A class encapsulates data and functions that manipulate data. Unlike other programming languages such as Java and C#, JavaScript classes are syntactic sugar over the prototypal inheritance. In other words, ES6 classes are just special functions.

194
Q

What is Webpack?

A

It is a module bundler and allows you to compile javascript modules by generating a single (or few) files that run the application.

195
Q

How do you add a devDependency to a package?

A

Npm install –save-dev

Examples:

  • -save-dev webpack,
  • -save-dev webpack-cli,
  • -save-dev babel-loader
196
Q

What is an NPM script?

A

Way to bundle common shell commands, in our case, inside the package.json file. For us it was “build:”: “webpack”

You can link any made-up property name to a shell command as a value.

197
Q

How do you execute Webpack with npm run?

A

Ensure that there is a “build” property with a “webpack” value in the scripts object in package.json file. The type Npm run build in the shell.

198
Q

What does fetch() return?

A

fetch() returns a promise which is fulfilled once the response is available. The promise resolves to the Response object representing the response to your request.

199
Q

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

A

GET method

200
Q

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

A

In the init object as the second argument in the fetch function.
fetch(‘https://jsonplaceholder.typicode.com/users’, { method: ‘GET’ })