JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Store information for the script to its job.

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

How do you declare a variable?

A

First use the variable keyword, then the variable name.

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

After the variable name use the equal sign or assignment operator then the variable value.

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

What characters are allowed in variable names?

A

letters, underscore, dollar sign, 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

The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of 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

Working with any kind of text. Represent and manipulate 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

Working with numeric data.

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

Create true or false statements. Determine which part of a script should run.

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

Is an assignment operator. Is used to give the 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

Just use the variable name, the equals sign and the new value.

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

Undefinided is a variable has been declared but has not been assigned a value. Null is an assignment value. It can be assigned to a variable as a representation of no 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

Is good to avoid confusions between similar values.

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, null, undefined.

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

What data type is returned by an arithmetic operation?

A

Numerical value.

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

The addition operator ( + ) produces the sum of numeric operands or string concatenation

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

A boolean value (true or 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

The addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result to the variable.

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

What is string concatenation?

A

Join two or more strings values into one value.

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

What are object properties?

A

An association between a name (or key) and a value

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

Describe object literal notation.

A

Value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last one

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

How do you remove a property from an object?

A

Using the delete operator.

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

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

A

With a dot and with brackets.

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

What are objects used for?

A

For store data as properties (key-value pairs).

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

What are arrays used for?

A

Used to store values that are related to each other.

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

Describe array literal notation.

A

a list of zero or more expressions, each of which represents an array element, enclosed in square brackets ( [] )

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

What number represents the first index of an array?

A

zero.

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

What is the length property of an array?

A

size of the array or the total number of elements present in the array.

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

How do you calculate the last index of an array?

A

Get the last element of ArrayList with use of get(index) method by passing index = size – 1.

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

How are arrays different from “plain” objects?

A

Arrays are used when we store multiple values ​​of a single variable, while an object can contain multiple variables or properties with their values.

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 JavaScript function is a block of code designed to perform a particular task.

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
    • Optional name.
    • Parameters separated by a comma.
    • Opening curly brace { for the code block.
    • Optional return.
  1. -Closing curly brace} for the 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

The function’s name. A comma separated the arguments surrounded by parentheses.

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

Define a function doesn’t cause the code block run because is just an object. Call an object does the code block run.

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 the name within the function definition.

Arguments are the values passed in when the function is called.

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
    • Causes the function to produce a value we can use in our program
    • Used to stop the function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Why are function parameters useful?

A

They received the arguments that are passed when the function is called.

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

What are the four components of “the Cascade”.

A
    • Source order
    • Inheritance
    • Specificity
    • !important
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Why do we log things to the console?

A

to verify that what we are doing is correct

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

What is a method?

A

Is statement or code block that performs a specific task.

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

How is a method different from any other function?

A

Method is function that belongs to an object while function not.

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

How do you remove the last element from an array?

A

With pop method

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

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

A

Math.floor method

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

How do you generate a random number?

A

Random method

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

How do you delete an element from an array?

A

splice method

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

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

A

No, we can console.log the original variable

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

Give 6 examples of comparison operators.

A

strictly equal(===), not equal to (!=), not strict equal to(!==), greater than (>), less than(<), greater or equal than (>=), less or equal than (<=).

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

What data type do comparison expressions evaluate to?

A

Boolean values

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

Is else required in order to use an if statement?

A

No

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

What are the three logical operators?

A

logical and(&&), logical or (| |), logical not (!)

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

Syntax of an if statement

A

if keyword, condition, opening curly brace, code to execute if value is true, closing curly bracket

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

What is the purpose of a loop?

A

repeat the same, or similar, code a number of times. Simplify work.

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

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

A

tested each time the loop repeats.

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

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

A

sequence of instructions that is continually repeated.

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

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

A

An expression evaluated before each pass through the loop.

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

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

A

before the execution of the first loop.

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

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

A

each time before the loop runs.

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

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

A

This expression is executed after each iteration of the loop

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

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

What does the ++ increment operator do?

A

increases the value of a variable by 1

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

How do you iterate through the keys of an object?

A

With for..in loops.

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

Why do we log things to the console?

A

Test if what we did works before to print the final result to the user.

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

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

A

HTML document

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

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

A

Represent each object that conform the structure and content of a document on the web.

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

What is a DOM Tree?

A

Structure of nested nodes.

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

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

A

querySelector() and getElementById()

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

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

A

getElementsByClassName()

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

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

A

If you want to work with that element more than once

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

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

A

console.dir()

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

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

A

Because the browser needs to parse all of the elements in the HTML page before JavaScript code can access them.

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

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

A

Takes a string that contains css selector describing the HTML element you want to work with. Returns only the first of the matching elements

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

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

A

Takes a css selector and returns all of those that match.

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

What is a model?

A

a representation of something else

76
Q

Why do we log things to the console?

A

To see how our code is working

77
Q

What is the purpose of events and event handling?

A

Allows the page to be interactive

78
Q

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

A

.addEventListener()

79
Q

What is a callback function?

A

A call back function is a function that is passed into another function as an argument.

80
Q

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

A

Event object

81
Q

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

Where interactions occurred. You can log it or with debugger. MDN

82
Q

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

The first one runs the eventlistener when the event is fired. The last one indicates that the event listener should run as the page loads

83
Q

What is the className property of element objects?

A

A string containing the value of a class attribute on that element.

84
Q

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

A

With classname property: .className

85
Q

What is the textContent property of element objects?

A

Is a string containing the value of the text content of an element

86
Q

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

A

By using textContent property

87
Q

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

A

Not always

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

89
Q

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

A

Easier access for later use

90
Q

Give four examples of CSS transform functions.

A

Matrix, translate, scale, rotate, skew.

91
Q

What does the transform property do?

A

Lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.

92
Q

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

A

Focus control

93
Q

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

A

blur event

94
Q

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

A

input event

95
Q

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

A

submit event

96
Q

What does the event.preventDefault() method do?

A

Prevents the default function of an element

97
Q

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

A

Reloads the page

98
Q

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

A

elements property

99
Q

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

A

value property

100
Q

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

A

You don’t know if or where things are failing.

101
Q

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

A

Ability to check if your code is working.

102
Q

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

A

No, it only creates an element, but does not insert it into the page. .

103
Q

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

A

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

104
Q

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

A

two string representing an attribute and its value

105
Q

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

A

create the element, give the element some content, and insert the element into the page.

106
Q

What is the textContent property of an element object for?

A

setting or getting text of an element

107
Q

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

A

.setAttribute and .className

108
Q

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

A
    • automate repetitive work

- - can be reusedcan change it anytime

109
Q

What is the event.target?

A

The element most directly interacted with by an event. The target of the event (most specific element interacted with)

110
Q

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

A

event bubbling

111
Q

What DOM element property tells you what type of element it is?

A

tagName

112
Q

What does the element.closest() method take as its argument and what does it return?

A

A selector containing a selector list, and it returns the element which is the closest ancestor of the element.

113
Q

How can you remove an element from the DOM?

A

.remove()

114
Q

If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?

A

Adding event listener to the parent that will contain the new item with bubbling event

115
Q

What is the event.target?

A

The object of that event is ocurring

116
Q

What is the affect of setting an element to display: none?

A

Turns off the display of an element and acts as if it was not there.

117
Q

What does the element.matches() method take as an argument and what does it return?

A

It takes a selector in the form of a string and returns a boolean.

118
Q

How can you retrieve the value of an element’s attribute?

A

.getAttribute() method

119
Q

At what steps of the solution would it be helpful to log things to the console?

A

Every step

120
Q

If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?

A

you would have to add an event listener for each tab and view

121
Q

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

many if/else statements.
t would have more code to check every tab.
conditionals for for each one

122
Q

What is JSON?

A

JavaScript Object Notation and it is lightweight data-interchange format.

123
Q

What are serialization and deserialization?

A

serialization: converting a native object to a string so it can be transmitted across the network or it can be stored
deserialization: Converting a string to a native object

124
Q

Why are serialization and deserialization useful?

A

Sending information over a network.
for data exchange and storing data without having to rely on it storing as a reference in your computer

it allows you to save the state of an object and convert it to 1s and 0s so it can be transferred over networks and then it can be translated back into an object through deserialization

125
Q

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

A

JSON.stringify( ) method

126
Q

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

A

JSON.parse( ) method

127
Q

How do you store data in localStorage?

A

call the setItem method of the localStorage object.

128
Q

How do you retrieve data from localStorage?

A

call the getItem method of the localStorage object.

129
Q

What data type can localStorage save in the browser?

A

key/value pairs in the form of strings.

130
Q

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

A

just before the program closes, while the content is still visible.
The beforeunload event is fired when the page is about to be unloaded.
Before everything is dumped out of the memory from the browser.

131
Q

What is a method?

A

A function which is a property of an object.

132
Q

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

A

A method definition has the keyword function and the code block following it. A method call only has the argument inside of the method.

133
Q

Describe method definition syntax (structure).

A

property name followed by the function keyword and its parameters. And then a code block that has the necessary code.

134
Q

Describe method call syntax (structure).

A

object followed by a period and the property after. And then parenthesis to hold the given arguments for that method call.
object.methodName()
obj, method name, arguments.

135
Q

How is a method different from any other function?

A

A method is a property thats defined within that object, while a normal function is a method of the global scope (window).

136
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

137
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

138
Q

What is “abstraction”?

A

Being able to work with (possibly) complex things in simple ways.

139
Q

What does API stand for?

A

Application Programming Interface

140
Q

What is the purpose of an API?

A

To allow a programmer a way to interact with a system in a simplified way.

141
Q

What is this in JavaScript?

A

An implicit parameter that allows us to see the object that ‘this’ is being invoked upon.

142
Q

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

A

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

143
Q

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

A

When function is called

The value of this is determined when the function is called, not when it is defined.

144
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

Mario

145
Q

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

A

The greet method of the character object is call. This method includes a string that is concatenated with this.FirstName.
It would return: ‘It’s-a-me, Mario!’
Because character is the object which contains the method ‘greet’, which refers to the firstName property of character in its codeblock

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

undefined.

this is attached to hello when it is called with hello. hello does not have a firstName property. this is attached to whoever is calling the function.

It returns the message + undefined because this.firstName isn’t defined within the variable hello. This keyword is now attached to hello rather than the firstName property of the character object.

147
Q

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

A

you can’t tell until the method or function is called.
you can tell what [this] will be because it is attached to an object. so [this] is referring the object that it is contained in.

148
Q

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

A

look at the object left of the dot when the function or method is being called

149
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype based

150
Q

What is a prototype in JavaScript?

A

An object that contains properties and (predominantly) methods that can be used by other objects.

151
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

Those methods are defined on a “prototype” object and arrays simply borrow those methods when they’re needed.

152
Q

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

A

The prototype chain

153
Q

What does the new operator do?

A

Creates a new instance of an object.

Creates a blank object
Sets the constrcutor of new object to other object
Passes new object as this
Returns this if the function does not return an object

154
Q

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

A

Prototype

155
Q

What does the instanceof operator do?

A

Check if the object is inheriting from the specified object.
The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.
tests the presence of constructor.prototype in object’s prototype chain

156
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() method

157
Q

What is a “callback” function?

A

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.

158
Q

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

A

setInterval() method.

159
Q

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

A

The default time delay is 0, which executes immediately. or more accurately, the next event cycle.

160
Q

What do setTimeout() and setInterval() return?

A

The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout();

The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval()

161
Q

What is AJAX?

A

A technique for loading data into part of a page without having to refresh the entire page. Data is often sent in JSON format.
increasing the user experience and better performance.

162
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

163
Q

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

A

XMLHttpRequest()

164
Q

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

A

load event

165
Q

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

A

there is an EventTarget prototype object that is the prototype of the XMLHttpRequest that has the addEventListener method

both DOM elements and XMLHttpRequest objects inherit the method from the same prototype (EventTarget) that does have that method.

Both inherit the EventTarget method from the DOM interface
prototype chain
Both inherit the EventTarget method from the DOM interface

166
Q

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

A

A code block is a set of code that is grouped together, usually by using {}. Functions, loops, and conditionals have code blocks. - if/else, for, do while, while, try, catch, etc.

a chunk of code that will do a specific task when appropriate (when the function is called or a conditional is met/true)

167
Q

What does block scope mean?

A

the variables exist only within the corresponding block; variables are not visible outside the block

as opposed to function scoped.
inside the code block
- things that happen inside the curl braces.

block scope refers to the area within code block

variables exist only within the corresponding bloc

168
Q

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

A

block-scoped

169
Q

What is the difference between let and const?

A

The difference is that let is mutable while const is a read-only reference.

const keyword creates block-scoped variables whose values can’t be reassigned

let - mutable, const- immutable

170
Q

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

A
  • because we are not reassigning a block-scope, we’re just modifying the array held by the const variable
  • const’s values can change/be mutated, but it cannot be reassigned to a dif block-scope value
171
Q

How should you decide on which type of declaration to use?

A

If a variable is not going to need changing, const should be used. If the variable may need its value updated, let is the right way to declare.

is the whole variable being reassigned (let), or are just the values inside the variable changing (const)

arrays & objects, always CONST

172
Q

What is the syntax for writing a template literal?

A

wrap the string in backticks

any expressions or variables go inside curly braces with a dollar sign before

173
Q

What is “string interpolation”?

A

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

String interpolation is the process of evaluating a string that contains one or more placeholders(variables), which will be replaced by their appropriate values when the string is evaluated.

To replace variables and expressions with their values within a string.

174
Q

What is destructuring, conceptually?

A

Taking properties and values from an object and assigning their values to independent variable.

  • a way to assign the properties of an object to individual variables
  • to get values from an object.
    way of extracting multiple values from data stored in (possibly nested) objects and Arrays.
175
Q

What is the syntax for Object destructuring?

A

const {names you want to assign to your variables} = object

Declare a variable followed by the curly brace. Property names are assigned to variables with the colon sign in between. Followed by a closing curly brace. and that whole code block is assigned to a variable name.

const/let keyword,
curly braces,
variable names within curly brace,
assignment operator,
variable
176
Q

What is the syntax for Array destructuring?

A
const/let keyword,
brackets,
variable names,
assignment operator,
variable
177
Q

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

A

creating, on the right
destructuring, on the left

destructuring, check for variable name at the end

or if there is no variable name following const/let

178
Q

What is the syntax for defining an arrow function?

A

parameter list, arrow, codeblock

let funcName = (parameter) => { return expression; };

one param - param => expression (for anonymous)
multiple params - (param1, param2) => expression, requires parantheses
multiple statements - require body brackets and return

(param1, param2)=>{ return;}:
param=> exp;
()=>exp

179
Q

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

A

No return keyword is needed. The keyword return is implied for the body. If there are multiple expressions to compute, then the return won’t occur.

Function body is

180
Q

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

A

The value of this is determined at the time the arrow function is defined.

181
Q

What is a CLI?

A

command line interface. processes commands to a computer program in the form of lines of text

182
Q

What is a GUI?

A

graphical user interface. is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, instead of text-based user interfaces, typed command labels or text navigation.

is a system of interactive visual components for computer software. A GUI displays objects that convey information, and represent actions that can be taken by the user. The objects change color, size, or visibility when the user interacts with them.

183
Q
Give at least one use case for each of the commands listed in this exercise.
man
cat
ls
pwd
echo
touch
mkdir
mv
rm
cp
A

man- interface to online reference manuals (use when there’s a command you don’t know much about)

cat- concatenate files and print on the standard output (use when you want to see contents of file or even combine files together in a new file)

ls- list directory contents (when you want to see what is inside the current directory)
(-a do not ignore entries that start with .
- F append indicator to entries)

pwd- print name of current/working directory ( when you want to know which directory you are in currently)

echo- display a line of text (when you want to display text and possibly put that text into a file)

touch- create new files

mkdir- make directories
(-p makes parent directories as needed)

mv- rename files/directories

rm- delete files
(-r removes directories and all their contents
-f ignore nonexistent files and arguments, never prompt)

cp- copy files and directories
(-r copy directories recursively)

184
Q

What are the three virtues of a great programmer?

A

Laziness, Impatience, Hubris

185
Q

What is Array.prototype.filter useful for?

A

It is useful for creating a new array when you only want to grab specific values from an existing array that meet a specific condition.

186
Q

What is Array.prototype.map useful for?

A

when you want to run a function on every index in the array and return the same amount of values as the input array

creating a new array containing the values resulting from calling a provided callback function on each value of an array

187
Q

What is Array.prototype.reduce useful for?

A

for reducing an array to a single value using a provided callback function

When you want to run a function on every index in the array and return a single value