JavaScript Flashcards

1
Q

JS-primitives-and-variables

What is the purpose of variables?

A

= To store data/information that needs to do its job, and give that job a keyword(name), so that it can be used later on.

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

JS-primitives-and-variables

How do you declare a variable?

A

= var keyword, declare variable name, followed by semicolon

ex. var coding;

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

JS-primitives-and-variables

How do you initialize (assign a value to) a variable?

A

use assignment operator ( = ), and give variable a value, followed by semicolon. ( ex. quantity = 3;)

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

JS-primitives-and-variables

What characters are allowed in variable names?

A

= Letter, $ sign, or (_) underscore.
= Cannot start with a number. (but can have number in var names)
= Do not use dash (-) or a period (.)
= Cannot use keywords or reserved keywords (such as var, let, const, etc)
= Use camel case (ex. firstName)
= letters(upper or lowercase), numbers(not start with the numbers), and $ sign

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

JS-primitive-and-variables

What does it mean to say that variable names are “case sensitive”?

A

= “Score” and “score” will be treated as different variable names.
= Computers treat uppercase and lowercase as they have no relationship.

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

JS-primitives-and-variables

What is the purpose of a string?

A

= To work with any kinds of texts

= Store or manipulate text.

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

JS-primitives-and-variables

What is the purpose of a number?

A

= To work with numeric data types

= For math: calculate, holding numeric values

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

JS-primitives-and-variables

What is the purpose of a boolean?

A

= Give a value of true or false. Script to run either or options
= Binary logic: on/off, true/false, yes/no

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

JS-primitives-and-variables

What does the = operator mean in JavaScript?

A

= it assigns a value to a variable.

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

JS-primitives-and-variables

How do you update the value of a variable?

A

=Set a new value using the assignment operator.

** Var const, let, keyword is not required for updating the value

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

JS-primitives-and-variables

What is the difference between null and undefined?

A

= Null: can only exist when assigned. Null cannot be created by js.(purposeful emptiness = we’re gonna fill it later, or just for a purpose.)
= Undefined: js tells when value is empty. Js creates undefined. Developers don’t assign undefined.

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

JS-primitives-and-variables

Why is it a good habit to include “labels” when you log values to the browser console?

A

= to help you debug easily by looking for a label.
A console log “label” is simply a short string that describes the variable or value being logged.
= To easily find where the problem is happening.

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

JS-primitives-and-variables

Give five examples of JavaScript primitives.

A
= Sting
= Number
= Boolean
= Null
= Undefined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

JS-operators-and-expressions

What data type is returned by an arithmetic operation?

A

=Numeric value (number)

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

JS-operators-and-expressions

What is string concatenation?

A

= Connecting strings, variables, or functions to log in a single line
= Addition for strings to variable.
= strings are immutable (cannot be edited) after created.
= Concatenation makes a new string, not changing the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
JS-operators-and-expressions
What purpose(s) does the + plus operator serve in JavaScript?
A

= Addition of values(number, string, etc) to the existing variable’s value
= Concatenation of a string to a value.

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

JS-operators-and-expressions

What data type is returned by comparing two values (greater than sign, less than sign, === etc)?

A

= Boolean value: True or false

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

JS-operators-and-expression

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

A

= Adds whatever the value is on the right side of the operand.
= adds the value of the right operand to a variable and assigns the result to the variable.

a += b means a = a + b

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

JS-objects

What are objects used for?

A

= Grouping/storing multiple variables and functions

= Multiple data to work together.

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

JS-objects

What are object properties?

A

= Variable within a certain boundary.
=You have to state where they are coming from. Properties tend to be group with other stuff.
= Properties are the values associated with a JavaScript object.
= Properties can usually be changed, added, and deleted, but some are read only.

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

JS-objects

Describe object literal notation.

A

= object name , assignment operator (=), followed by opening curly brace ({)
= And some variables (called keys/properties) with values separated with colon (:), and closed with closing curly brace (}), and semicolon (;).

var person = { name: ‘John’, age: 30, eyeColor: ‘blue’};

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

JS-objects

How do you remove a property from an object?

A

=delete objectname.key
= delete operator (delete)

delete Employee.firstname;

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

JS-objects

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

A

= use . notation or bracket notation, but using dot notation is preferred.

person.name = ‘David’

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

JS-arrays

What are arrays used for?

A

=Storing ordered/unordered lists

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

JS-arrays

Describe array literal notation

A

=Square brackets [ values stored inside the bracket, separated by comma. ]

var coffees = [‘French Roast’, ‘Colombian’, ‘Kona’];

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

JS-arrays

How are arrays different from “plain” objects?

A

= Have orders, numbered indexes, stored in square brackets.

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

JS-arrays

What number represents the first index of an array?

A

= 0

var shopping = [‘coffee’, ‘bread’, ‘sugar’];

index of ‘coffee’ is 0
index of ‘bread’ is 1
index of ‘sugar’ is 2

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

JS-arrays

What is the length property of an array?

A

= counts the number of values/lists in the array

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

JS-arrays

how do you calculate the last index of an array?

A

= subtract 1 from the total length.

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

JS-functions

What is a function in JavaScript?

A

= Group of tasks that is repeatable / reusable block of code.
=a set of statements that performs a task or calculates a value

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

JS-functions

Describe the parts of a function definition.

A

= Function keyword, function name, followed by () for possible arguments, and opening { , code blocks to run when function is called, and followed by closing } , then semicolon ;
= Functions with receiving values and return result, or function to show result

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

JS-functions

Describe the parts of a function call.

A

= Function name, parentheses, inside parentheses, some/single argument/s, followed by semicolon ;

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

JS-functions

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

= Function definition has the whole process of code (keyword, arguments, code block, etc), function call only has the function name with argument(s)

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

JS-functions

What is the difference between a parameter and an argument?

A

= Argument is the placeholder for a function(no value), and argument is the actual values passed in when calling a function.

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

JS-functions

Why are function parameters useful?

A

= Putting an empty value in the function so that the function can be later used with the real values(arguments) passed in for repetitive function.

“parameters allow us to pass in any data at any time. If you create a function definition with the values pre-programmed into it, it would only ever be usable with that one set of data. We want an empty box that we can fill with different values at will.”

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

JS-functions

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

A

= Executes the code block in the function.
= Exits the code block, and returns the value of the code block.
*Return = escape hatch

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

JS-methods

Why do we log things to the console?

A

= To see if the code is working as it is directed
= Intended to be used for debugging.
= 0 usage in production of code. (user will never see console.log) delete console.log when you’re done debugging

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

JS-methods

What is a method?

A

= Function saved in the object

= A function that is property of an object.

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

JS-methods

How is a method different from any other function?

A

= Methods are function that is stored in the object.

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

JS-methods

How do you remove the last element from an array?

A

= Using .pop()

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

JS-methods

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

A

= Use Math.floor() = chops the decimal, but negative number gets lower value
= Math.trunc() = real chopping decimal value w/o lowering value

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

JS-methods

How do you delete an element from an array?

A

= .splice() - remove or replace existing elements and/or add new elements in the array. (arbitrary removal)

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

JS-methods

How do you append an element to an array?

A

= .push() - adds element/s to the end of an array

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

JS-methods

How do you break a string up into an array?

A

= .split() = give a character/value where the string needs to be split

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

JS-methods

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

A

= They don’t change the original, and use console.log to check.

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

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

A

= ~30 methods

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

JS-methods

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

A

No. (but they are designed to calculate possible outcomes

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

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

A

= ~25

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

JS-if

Give 6 examples of comparison operators.

A
Greater than ()
Strictly equal to ( ===)
Greater than or equal to  (>=)
Less than or equal to ( <=)
Strict not equal to ( !==)
Equal to ( ==) // never use!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

JS-if

What data type do comparison expressions evaluate to?

A

= boolean(t/f)

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

JS-if

What is the purpose of an if statement?

A

= To create a conditional statement to code to do a decision

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

JS-if

Is else required in order to use an if statement?

A

= No. optional. If you have a fallback.
= If else is added , either of the code will run. (if statement or the else statement).else: something is always going to happen

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

JS-if

Describe the syntax (structure) of an if statement.

A

= if keyword, (conditions) { opening for code block, some code to run if the condition is true, and closing } for closing code block.

=If keyword, condition, set of curly braces to wrap a code block, if that condition is true.

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

JS-if

What are the three logical operators?

A

= && (and) operator,
= || (or) operator,
= ! (not) operator

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

JS-if

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

A

= Use logical(&& or ||) operator.

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

JS-loops

What is a purpose of a loop?

A

= to perform (repeat) a code block based on a condition.
= typically return a boolean value.
= loop will run until the defined condition returns false.

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

JS-loops

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

A

= to give a condition when the code block should execute/stop.
** condition is a stop point for a loop

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

JS-loops

what does ‘iteration’ mean in the context of loops?

A

= one repetition of a code block.

= each time the computer runs through a loop.

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

JS-loops

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

A

=before executing the statement.

= before the code block runs

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

JS-loops

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

A

= evaluated ‘once’ before the loop begins

= in the beginning, before anything in the loop.

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

JS-loops

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

A

= evaluated before each loop iteration.
= if evaluates true, statement in the code block is executed.
= if evaluates false, execution skips to the first expression following the for construct. (** condition test is optional)

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

JS-loops

when does the final expression of a ‘for’ loop get evaluated?

A

= at the end of each loop iteration. this occurs before the next evaluation of condition.
= generally used to update or increment (++) the counter variable(i).
= after the iteration. final expression happens after each iteration.

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

JS-loops
besides a ‘return’ statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to ‘false’?

A

= break;

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

JS-loops

what does the ++ increment operator do?

A

= updates the counter variable(i), by adding 1.

= adds and assigns the value by 1.

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

JS-loops

how do you iterate through the keys of an object?

A

= using for…in loop

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

JS-DOM-querying

Why do we log things to the console?

A

= to check if the code is functioning as expected

= for debugging

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

JS-DOM-querying

What is a ‘model’?

A

= structure (car model, blueprint for house)

= HTML document

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

JS-DOM-querying

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

A

document = HTML document

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

JS-DOM-querying

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

A

= Data type object in javascript
= DOM is a recreation of a data as js object, to interact with
= DOM is the intermediary, the middle man. Allows javascript to influence HTML and CSS.

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

JS-DOM-querying

What is a DOM Tree?

A

= Any HTML documents with nodes (elements, attribute, text)
= Element with all other child, parent elements
= a model of a web page

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

JS-DOM-querying

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

A
= Use document.querySelector() => always works by element type, class name, element with certain class, overall it gives consistency to access.
= Use document.getElementById()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

JS-DOM-querying

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

A

= getElementsByClassName()

= querySelectorAll()

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

JS-DOM-querying

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

A

= If you want to access multiple times, so that you don’t have to code it out.
= You don’t need to search for it again.

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

JS-DOM-querying

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

A

= console.dir() dir method

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

JS-DOM-querying

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

A

= So that HTML can run before JS runs.

= If script tag is in the beginning of body tag, then JS will run first before HTML

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

JS-DOM-querying

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

A

= Takes CSS selector as argument, returns first element in the HTML that fits

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

JS-DOM-querying

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

A

=Takes CSS selector, and returns all of the elements in the nodeList.

  • NodeList is an array like objects. Is not an array. Object with properties that are numbers.
  • Reason for being object, it forces you to not to add new stuff into it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

DOM-events

What is the purpose of events and event handling?

A

= event: indicate which event on the selected node will trigger the js code. things that happen/ user control.

= event handling: to set up the whole procedure for js code to trigger. creating response to an event.

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

DOM-events

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

A

=No.

=Third parameter for addeventListener(), that’s (useCapture)boolean value, which is optional.

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

DOM-events

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

A

= addEventListener()

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

DOM-events

What is a callback function?

A

= Function definition passed in as an argument.
= In JS, function definitions are values that you can pass around as arguments in other functions. (AKA, callback function).

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

DOM-events

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

A

= event object. (you can name other things, but event is much more clear). To indicate the function definition is for addEventListener()’s callback function.

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

DOM-events

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

A

= property on that event object , whose value is the element that where it (event) occurred. => where the event actually occurred. (not where the event is attached)

= event.target target: holds reference, where the event originated from (occurred).

84
Q

DOM-events

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick) => CORRECT
element. addEventListener(‘click’, handleClick()) => INCORRECT

A

= Top one : handleClick is referenced.
= Bottom one: function handleClick() is being called.

**It will not function as an eventHandler, it will call the function, then it will not be a callback function. It will throw an error

85
Q

DOM-manipulation

What is the className property of element objects?

A

= className property get or set the value of the class attribute of any element

86
Q
DOM-manipulation
How do you update the CSS class attribute of an element using JavaScript?
A

= className property, and assign the with new attribute.

87
Q

DOM-manipulation

What is the textContent property of element objects?

A

= used to set text content for the HTML element or get the text content written inside that element.

88
Q

DOM-manipulation

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

A

= queryselector and get new value of the element and assign

= Use the textContent property to change the text of a span element

89
Q

DOM-manipulation

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

A

= no

90
Q

DOM-manipulation

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

A

= Complicated: switching string to number through HTML is more complicated.

91
Q

DOM-manipulation

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

A

= Makes much easier to fix. JS can use that information to make adjustment.

92
Q

JS-forms

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

A

= focus

93
Q

JS-forms

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

A

= blur

94
Q

JS-forms

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

A

= input event

95
Q

JS-forms

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

A

= submit event

96
Q

JS-forms

What does the event.preventDefault() method do?

A

= Prevents default behavior from an event.

= Prevent from reloading the page.

97
Q

JS-forms

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

A

= Allows default behavior (refreshes/reload the entire page)

98
Q

JS-forms

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

A

= Elements property. Value of the element property is an object (representing form controls)

99
Q

JS-forms

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

A

= Value property

= Value property store what’s currently stored

100
Q

JS-forms

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

A

= Hard to see/ find where the code went wrong

101
Q

JS-forms

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

A

= Console will show any errors.

= A way of communicating with javascript to fix any errors.

102
Q

DOM-creation

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

A

= No. it only creates the element node.

103
Q

DOM-creation

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

A

= Using appendChild() method
= elementName.appendChild(‘text or element that want to be appended’)
= Another option: append() => this lets append multiple elements.
= append(multiple elements)

104
Q

DOM-creation

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

A

= Name (name of the attribute), and value (value to assign to the attribute).
= Name of the attribute, value of the set attribute.

105
Q

DOM-creation

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

A
  • First, create the element node
  • Second, give the element a content, using createTextNode() method
  • Third, append the text node to element node using appendChild()
  • Fourth, find the position where the new element will be added.
  • Last, append the element to DOM ( using appendChild() method.
  • *** Parent is the method you call on, and child is the one you append it.
106
Q

DOM-creation

What is the textContent property of an element object for?

A

= Assigns new text, or update text value

107
Q
DOM-creation
Name two ways to set the class attribute of a DOM element.
A

= ClassName property, and setAttribute method.

108
Q

DOM-creation

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

A

= You can reuse that behavior

= You can give a name to a process, and recognize what it does.

109
Q

DOM-delegation

What is the event.target?

A

= Whatever you click on

= element where the event is originally started from.

110
Q

DOM-delegation

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

A

= Because of the event bubbling.
** The process is called “bubbling”, because events “bubble” from the inner element up through parents like a bubble in the water.

111
Q

DOM-delegation

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

A

= tagName property = values are always string with all caps( ex. “BUTTON”)

112
Q

DOM-delegation

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

A

= Takes CSS selector as an argument,
= Returns the first ancestor that matches the pattern.
= Almost like a queryselector.

113
Q

DOM-delegation

How can you remove an element from the DOM?

A

= Use .remove() method

= Call it on the element you want to remove, and use remove method

114
Q

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

= Use addEventListener to an ancestor element.

115
Q

JS-view-swapping

What is the event.target?

A

= DOM object representing element where the event originally happened.

116
Q

JS-view-swapping

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

A

= Makes element invisible.

117
Q

JS-view-swapping

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

A

= String of CSS selector
= Return boolean / whether the CSS selector matches the element you called on. (using matches() method to check it that matches)

118
Q

JS-view-swapping

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

A

= Using getAttribute() method with argument of (name/value of string, and return attribute)

119
Q

JS-view-swapping

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

A

= EVERY SINGLE STEPS

120
Q

JS-view-swapping
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

= Add a eventlistener every single tab.

not recommended!

121
Q

JS-view-swapping
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

= Separate conditional blocks for each separate page.

= Not recommended. For later adding pages : you will have to create every conditional blocks for additional pages.

122
Q

JS and JSON

What is JSON?

A

JavaScriptObejctNotation
= JSON is Data interchanging format, not behavior changing format.
= text-based data format following JavaScript object syntax.
= JSON is a lightweight format for storing and transporting data
= JSON is often used when data is sent from a server to a web page
= JSON is “self-describing” and easy to understand
= JSON requires double quotes to be used around strings and property names. Single quotes are not valid other than surrounding the entire JSON string.
= Format that can be parsed out anywhere, interchangeable format, non serialized to serialized.

123
Q

JS and JSON

What are serialization and deserialization?

A

= Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.
= Deserialization is the reverse process: turning a stream of bytes into an object in memory.
= S: takes data into one contiguous series of bytes (string)
= D: spread out the string to everywhere

124
Q

JS and JSON

Why are serialization and deserialization useful?

A

= Serialization means transforming something (e.g. my dog Rex photo) into a series of 1s and 0s - which can be transported over the phone line, stored in memory. My friends overseas can then translate those 1s and 0s back into a perfect representation of a puppy photo (de-serialization) so they can enjoy Rex’s photo/image.
= Serialization to preserving the data
= D: make it easy to access data, manipulate the data. Using data

125
Q

JS and JSON

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

A

= Store as a JS object, but put single quotes around the object/array and store properties with double quotes.
= JSON.stringify()

126
Q

JS and JSON

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

A

= Using JSON.parse()

127
Q

JS-local-storage

How do you store data in localStorage?

A

= Using setItem() method

128
Q

JS-local-storage

How do you retrieve data from localStorage?

A

= Using getItem() method

129
Q

JS-local-storage

What data type can localStorage save in the browser?

A

= strings

130
Q

JS-local-storage

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

A

= when the window, the document and its resources are about to be unloaded.
= Before the page loads. (anything that will make the current page go away, the ‘beforeunload’ event will fire.

131
Q

JS-custom-methods

What is a method?

A

= A function saved in object as a property

132
Q

JS-custom-methods

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

A

= Method definition has a whole function definition with parameters, method call is just like dot notation with arguments
methodDefinition: actual function definition, stored as property of an object
Call method: named of the object with properties. (. notation)

133
Q

JS-custom-methods

Describe method definition syntax (structure)

A

= Method name, colon, then method definition, opening { for code block, some code, then } for closing code block.
Ex: fullName: function() {
return this.firstName + “ “ + this.lastName;

134
Q

JS-custom-methods

Describe method call syntax (structure).

A

= Object name, dot , and method name (just like dot notation in object property)
Ex.) name = person.fullName();

135
Q

JS-custom-methods

How is a method different from any other function?

A

= It’s saved in the object as a property

= Use dot notation to call the method.

136
Q

JS-custom-methods

What is the defining characteristic of Object-Oriented Programming?

A

= OOP is all about containing data as property and behavior

= Containing data and behavior saved in a same bubble

137
Q

JS-custom-methods

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

A

= Abstraction
= Encapsulation
= Inheritance
= Polymorphism

138
Q

JS-custom-methods

What is “abstraction” in OOP?

A

= being able to work with (possibly) complex things in simple ways.
= Simplifying a complex process to a simple process without having to fully understand how that complex process works. (ex. Light switch, DOM API)

139
Q

JS-custom-methods

What does API stand for

A

= Application Programming Interface

140
Q

JS-custom-methods

What is the purpose of an API?

A

= Have connection between computers or computer programs.
= to simplify programming by abstracting the underlying implementation and only exposing objects or actions the developer needs.

141
Q

JS-this

What is ‘this’ in JavaScript?

A

= In an object method, ‘this’ refers to the object. Alone, ‘this’ refers to the global object

142
Q

JS-this

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

A

= Implicit parameter, we don’t need to specify, but it’s present.
= Implicit means implied, but assumed to be present.
= “this” is not physically present all the time, but implicitly present all the time.

143
Q

JS-this

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

A

= Call time

= ‘this’ carries no meaning UNTIL the method is called(invoked)

144
Q

JS-this

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

A

= You can’t tell until you see the action

145
Q

JS-this

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. When a method is called.
= If there is no dot, it’s window object.
= *** Don’t use ‘this’ in the global scope (window object). Only use ‘this’ in the object literal you created.

146
Q

JS-prototypes

What kind of inheritance does the JavaScript programming language use?

A

= JavaScript includes a specific kind of inheritance known as prototype-based (or prototypal) inheritance. JavaScript objects give certain behaviors (methods) or data (properties) to other objects.

147
Q

JS-prototypes

What is a prototype in JavaScript?

A

= It is a mechanism by which JavaScript objects inherit features from prototype.
= global property creating a channel to other behavior(methods)

148
Q

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

= Because they Inherit from the prototype object

149
Q

JS-prototypes

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

A

= prototype

150
Q

JS-constructors

What does the new operator do?

A

= new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
= Creates a blank, plain JavaScript object.
= Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
1. Make blank object nothing in it
2. Take prototype property into new object (__proto__)
3. Gives ‘this’ var a value
4. Return ‘this’

151
Q

JS-constructors

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

A

= prototype property

152
Q

JS-constructors

What does the instanceof operator do?

A

= 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.
= The instanceof operator tests the presence of constructor.prototype in object’s prototype(prototypal) chain.

153
Q

JS-timers

What is a “callback” function?

A

= Function passed in to a another function as an argument

154
Q

JS-timers
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() = set up a time period, and execute AFTER the time

155
Q

JS-timers

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

A

= Use setInterval() = a loop, doesn’t happen all at once, happens in a period of time (delay of each iteration)

156
Q

JS-timers

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

A

= 0

157
Q

JS-timers

What do setTimeout() and setInterval() return?

A

= Returns interval ID, to clearout the setInterval().

158
Q

http-message

What is a client?

A

= Client is a service request

= Requesting something from somewhere. Consuming data from elsewhere, asking for something

159
Q

http-message

What is a server?

A

= Client asks for data, and server provides data.

= computer program or device that provides a service to another computer program and its user(client)

160
Q

http-message

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

A

= GET

161
Q

http-message

What three things are on the start-line of an HTTP request message?

A
  1. HTTP method - like GET, POST,
  2. The request target, usually a URL, or the absolute path of the protocol, port, and domain are usually characterized by the request context.
  3. The HTTP version, which defines the structure of the remaining message, acting as an indicator of the expected version to use for the response.
162
Q

http-message

What three things are on the start-line of an HTTP response message?

A

= Protocol version
= Status code
= Status text

163
Q

http-message

What are HTTP headers?

A

= Lines of code after start-line of HTTP

= Meta data of HTTP - like head element in the HTML document

164
Q

http-message

Is a body required for a valid HTTP request or response message?

A

= No.

= Ex: 201 message in HTTP. (201: data was created)

165
Q

JS-ajax

What is AJAX?

A

= A technique for loading data into part of a page without having to refresh the entire page

166
Q

JS-ajax

What does the AJAX acronym stand for?

A

= Asynchronous JavaScript And XML

167
Q

JS-ajax

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

A

= XMLHttpRequest()

168
Q

JS-ajax

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

A

= ‘load’ event is fired

169
Q

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

A

= They share the event target prototype

= Inheritance of prototype, is possible to share common prototype

170
Q

ES6- const-and-let

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

A

= Code block is denoted by curly braces ( { } )

= Examples are code blocks in function, loop, if statements, etc.

171
Q

ES6- Const-and-let

What does block scope mean?

A

= Block scope means that variables defined within a block will not be accessible from outside of the block

172
Q

ES6- Const-and-let

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

A

= They are block scoped

173
Q

ES6- Const-and-let

What is the difference between const and let?

A

= let can be mutated, but const cannot be mutated.

= const creates a read-only reference to a value.

174
Q

ES6- Const-and-let

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

A

= The value of const variable is showing the memory of the const, so the contents inside const can be updated, not the actual values.

= Usiung the methods to const is not re-assigning or re-declaring it, it’s just add/delete to the list that the const points to.

175
Q

ES6- Const-and-let

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

A

= depends on which value you’re assigning.
= if the values cannot be mutated, use const.
= if values will be updated later, use let.
= But in default, use const. If you need to update or change it later, then switch to let.

176
Q

ES6-template-literals

What is the syntax for writing a template literal?

A

= Using a backtick ( ` ) to wrap a string, and use $ { } to express any variables or functions.

177
Q

ES6 - template-literals

What is string interpolation?

A

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

178
Q

ES6- destructuring

What is destructuring conceptually?

A

= unpack values from arrays, or properties from objects, into distinct variables.

179
Q

ES6 - destructuring

What is the syntax for object destructuring?

A

= let { property1: variable 1, property2: variable2 } = object;

= The identifier before the colon ( : ) is the property of the object, and the identifier after the colon is the variable.

180
Q

ES6 - destructuring

What is the syntax for array destructuring?

A

= let [ x, y, z ] = newArray;

181
Q

ES6 - destructuring

How can you tell the difference between destructuring and creating object / array literals?

A
= destructuing: curly braces are on the left side
ex| : const { title, author, id } = library;
= assigning: curly braces are on the right side.
ex| : const title1 = libaray.title;
182
Q

ES6- arrow-functions

What is the syntax for defining an arrow function?

A

= Parentheses, possible parameters inside the parentheses, arrow, expression or statement in code block ( { } ).

183
Q

ES6- arrow-functions

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

A

= It will implicitly returns a value. Implying that the expression will return.

184
Q

ES6- arrow-functions

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

A

= takes the value from the block(parent) scope.
note: It is a good practice to use arrow functions for callbacks and closures because the syntax of arrow functions is cleaner.

185
Q

Command-line-basics

What is a CLI?

A

= Command-line interface, receive commands from a user in the form of lines of text.
= Anything you use in terminal is cli. (ex: git)

186
Q

Command-line-basics

What is a GUI?

A

= Graphic user interface.
= applications that use a GUI are usually aimed at consumers of technology (end users), not producers of technology (developers).
= Operating system (ex: compter, application, etc. ) using graphic to interact with data.

187
Q

Command-line-basics

man

A

= Manual to figure out how to use commands

= man is an interface to the on-line reference manuals.

188
Q

Command-line-basics

cat

A

= Concatenate files and print on the standard output

= List multiple files, move stuffs to files

189
Q

command-line-basics

ls (list segments)

A

= list directory contents.

= Sort entries alphabetically.

190
Q

command-line-basics

pwd (print working directory)

A

= print the filename of the current working directory

191
Q

command-line-basics

echo

A

= display a line of text (echos the string)

192
Q

command-line-basics

touch

A

= change file timestamps
= Creates text file (blank file)
= update the access and modification times of each FILE to the current time.

193
Q

command-line-basics

mkdir (make directories)

A

= Creates new directories
= After ls, anything starts with d represents directory.
= create the DIRECTORY(ies), if they do not already exist.

194
Q

command-line-basics

mv (move)

A

= move (rename) files

= Rename files or folders, or move files or folders to new location.

195
Q

command-line-basics
rm (remove)

**BE CAREFUL WITH THIS COMMAND, IT DELETES THINGS INSTANTLY, WITHOUT WARNING, AND CANNOT BE UNDONE.

A

= remove files or directories

196
Q

command-line-basics

cp (copy)

A

= copy files and directories

= copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

197
Q

command-line-basics

history

A

= many programs read input from the user a line at a time. The GNU history library is able to keep track of those lines, associate arbitrary data with each line, and utilize information from previous lines in composing new ones.

198
Q

Node-intro

What is Node.js?

A

= Server-side JavaScript runtime, set of libraries for JavaScript which allows it to be used outside of the browser.
= Allows us run js without browser

199
Q

Node-intro

What can Node.js be used for?

A

= It is commonly used to build back ends for web applications, command-line programs, or any kind of automation that developers wish to perform.

200
Q

Node-intro

What is a REPL?

A

= Read-eval-print-loop

= For testing code (sandbox playground)

201
Q

Node-intro

When was Node.js created?

A

= May 27, 2009

202
Q

Node-intro

What back end languages have you heard of?

A

= Ruby, Java, Python, PHP

203
Q

Node-process-argv

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

A

= The process is a global that provides information about, and control over, the current Node.js process
** (global here means it can be accessed anywhere in the program). (each program running on a computer represents a process).
= Global object that contains information about node process.

204
Q

Node-process-argv

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

A

= Just type process to access it.

205
Q

Node-process-argv

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

A

= Array.