javascript Flashcards

1
Q

What is a variable?

A

A keyword that’s used to store data.

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

Why are variables useful?

A

They can be ‘referenced’/re-used Any time and be used over and over again, thus saving time. If you don’t store data in a value (the return), then the computer does the calculations but that’s it. You won’t be able to retrieve that final result when you need it.

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

What two special characters can a variable begin with?

A

‘$’ and ‘_’ dollar and underscore. No dashes or periods in a variable name.

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

How do you declare a variable?

A

The ‘var’ keyword, then an identifier/variable name. One word written in camelCase.

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

How do you assign a value to a variable?

A

Var myVar = value. Equal sign then the value you want to assign.

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

Are variables case sensitive?

A

Yes

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

Which words cannot be used as variable names?

A

Other JS keywords or reserved words. ‘var’, ‘function’, ‘let’, etc. Numbers and symbols (besides $).

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

What is a string?

A

A primitive data type. A grouping of characters.

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

What is the string concatenation operator?

A

+ sign

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

What is the difference when it comes to using single quotes or double quotes (‘ ‘or” “)?

A

There is no difference in javascript, however if you want to use quotes inside of a string, you will have to escape them, or use the opposite (single or double quote) type of quote to surround the string.

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

How do youescapequotation characters?

A

Back slash before the character that needs escaping.

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

What is type coercion?

A

When two different data types are combined and both end up being one data type.
12+’hello’ turns into a string of ‘12hello’

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

What is a number in JavaScript?

A

Primitive data type that is any numeric value.

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

What is an arithmetic operator?

A

Something to perform mathematic equations.

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

Name four of the arithmetic operators?

A

+ - / % * ++ –

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

What is the order of execution?

A

Follows basic math, where multiplication and division happen before addition/subtration. Right hand side of equal sign, then left hand side. Use parenthesis to change order of operations. PEMDAS

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

What is a function?

A

Code that executes a code block. Collection of code that runs as one.

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

Why are functions useful?

A

They are -re-usable blocks of code. Saves time writing the same thing over and over. A way to store steps to be used later, for when functions don’t immediately run on page load.

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

How do you call a function?

A

Write out the function name with parenthesis and any arguments if you need them.

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

What are the parts of a function definition?

A

‘function keyword’, ‘function name’, parenthesis with parameters inside, and curly braces for the code block.

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

What is the difference between a parameter and an argument?

A

The are the same, however, it is a parameter when you are defining a function, and is an argument when when you are calling it.

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

Why is it important to understand truthy and falsy values?

A

So we can properly do comparisons without unintended results.

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

Why is the typeof an objectnull?

A

It’s a bug that is just accepted now because changing it would be the end of the internet.

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

What is the difference between null and undefined?

A

Null is purposefully set by the developer and denotes meaningful space. Undefined is generally an accident and is just straight up nothingness. Does not take up space in the memory.

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

Why do you always use===for comparisons?

A

Because loose equality == can cause type coercion and give weird results like when comparing 3 == ‘3’.

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

Why do you want to avoid using==for comparison?

A

Type coercion and unintended results due to it. Like 3 == “3”.

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

Do allifstatements require anelsestatement?

A

No

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

What is the proper syntax for using theoroperator?

A

Operand 1 || operand 2

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

What is the primary use case forswitches?

A

Comparing an individual value against a range of other individual values. 1 to 1 comparisons.

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

Does thedefaultcase have to be at the bottom of theswitchstatement?

A

No it does not. It is ‘else’ of switch statements, but doesn’t need to be at the bottom. But for good practice, you should put it at the bottom.

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

What happens if there is nobreakstatement betweencases?

A

It falls through to all subsequent cases and runs the code for each of them until it reaches a break or there are no more cases.

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

What is an object in JavaScript?

A

A group of variables and functions that create a model.
A collection of properties and methods grouped together.
It points to a memory address that points to where the data is actually stored,. Contrasted to primitive datatypes where the value is stored right at the variable.

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

How do you create an object literal?

A
Literal notation: Var newObject = { };
Object constructor notation: var newObject = new Object();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is a property in relation to JavaScript objects?

A

It tells us about the object, like traits or attributes. A place where we can store data inside of the object.

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

When should you use bracket notation over dot notation with objects?

A

When the property name is a variable or when the property name is an illegal character, like a space, or if its a number.

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

How do you remove a property from an object?

A

Delete myObj.myProp or myObj.myProp = “”;

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

What is an array in JavaScript?

A

An object that stores a list of values that are related to each other. Useful for when you don’t need to specify how many values it will hold. (shopping lists, ingredient lists).

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

How do you create an array literal?

A

Var myArray = [ ];

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

What are the keys for the values inside an array?

A

Numbers. Index positions, that start counting from ‘0’. [0].

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

Arrays have a property named length. Because arrays have a properties, what other data structure are they similar to?

A

Objects.

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

What are some good use cases for using objects inside arrays?

A

School directory, medical patient data base, any database where each index have similar properties. Shopping cart.

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

What is the primary advantage to storing your selected elements in a variable?

A

You don’t have to type out long dom queries over and over again when modifying them

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

Why might you need JavaScript to modify the DOM after the page loads?

A

It gives us interactivity with the user. We can update visuals after certain behaviors/actions
For maybe a ‘dark mode’ button on the page that converts all styling from light to dark.
For things like forms: clearing the form after submitting/resetting.

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

How can you better prepare when writing HTML for DOM manipulation in your JavaScript code?

A

Setting classes and ID’s appropriately? Structure your html (parents and children) in an organized way?

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

How to see all the info about the html document? The DOM, document object model.

A

Console.dir(document); This is our pathway from JS to the html and how it see’s the html and how will interact with it.

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

What are the differences betweeninnertextandtextContent?

A

similar to textContent but you should avoid it due to some browsers dont support it, it will not show any content that’s hidden by css. It also takes into account layout rules that specify whether the element is visible or not, so it can be slower than .textContent to retrieve content.

InnerText generally shows what you would visually SEE on the html. It doesn’t show hidden stuff. InnerText has to interpret the html AND any CSS that affects it. So it takes longer.

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

What datatype are the values you remove from a text input?

A

strings

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

Why is it so important to be able to dynamically update text?

A

So you don’t have waste time and bandwidth to reload the entire page to see changes. So the user can interact with the website. Making changes to the page after a user triggers an input.

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

What are some of the drawbacks of HTML Event Handler Attributes?

A

They are harder to make edits to later, especially if there are lots of elements with the same function? Makes code harder to read and hard to understand what the event is doing.

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

Why is the Window.event property useful for finding an element which was interacted with?

A

It shows x and y coordinates of the screen of where the event took place. And also the element that was clicked.

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

Why is the Window.event property to be avoided in new code?

A

Window.event changes with every single event. The value gets overwritten when a new event occurs. If you wanted to work with values of the event after it occurred, if another event happened in between that time, then you would be working off that new event. You would never know.

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

What is the difference between thegetElementById()method and thequerySelector()method?

A

GetElementById() returns the exact element with that ID. QuerySelector() targets the first element (using css selectors) within the document that matches the specified selector or group of selectors.

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

Who passes in the event object into thehandleClickcallback function?

A

Javascript automatically does it.

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

Does a callback function require a name?

A

No. You can have an anonymous function, but you should name them. Not reason not to.

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

What is the purpose of a loop?

A

To iterate through data quickly and automatically, saving time.

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

Why might there be different kinds of loops?

A

There may be different situations and conditions for what you need. If you know the exact amount of items you need to loop over, use a for loop. If you don’t know how many items there are, but you know when you need to end use a while loop.

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

What is the purpose of a conditional expression as it relates to loops?

A

It’s similar to a conditional statement in that, if the conditional statement is true, the code will run.

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

Could a loop potentially go on forever?

A

Yeah if a condition remains true (sometimes due to user-error syntax), and it will crash your browser.

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

Could a loop never start?

A

Yes, if the condition doesn’t result to true on the very first run, it will not run the first loop. Exception to this is a ‘do while’ loop, which will run one time.

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

How does aforloop differ from awhileloop?

A

How does aforloop differ from awhileloop?
A for loop is for when you know exactly how many items you need to loop over. A while loop is when you don’t know how many items, but you know when it should end. If an array keeps changing, like things getting deleted or added, that’s a good chance to use while loop.
While loops only need a condition. And for loops need a initilization and final expression ( to actually do something )? Watch vod.

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

What potential use cases are there forforloops?

A

Logging out a recipe/ingredient list. Student list. Todo list?

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

Which pieces of information provided in the parentheses for aforloop are mandatory?

A

None of them. The semi colons are required though. For (;;) { };

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

What is a for in loop?

A

A way to iterate through properties of an object.

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

How do you target the value of a property in an object.

A

Bracket notation. object[variable]

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

When should you use a for in loop?

A

When you want to loop over an object and do the same action on each property.
Good for debugging purposes, easy way to check the properties of an object (by outputting to console or otherwise). Though arrays are more practical for storing data, there are situations where a key-value pair is preferred (with properties acting as the ‘key’, and there may be instances where you want to check if any of those keys hold a particular value.

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

What is the difference between theparentNodeandparentElementproperties?

A

ParentElement will return null if the parent element is not an element. ParentNode will return things like white spaces as parents if a white space is present.

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

Why is it important to be able to traverse the DOM?

A

Flexibility in being able to target the exact elements you want to.

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

What kind of information is useful to store in custom attributes?

A

Useful information that describes the element? Easy ways for JS to access the element? Can use those custom attributes in JS to augment the page based on user interaction?
Clicking a fruit might trigger a pop up that shows info stored in a custom attribute like nutritional facts or something
-<img></img>

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

What are two ways to target elements on the DOM?

A

.querySelector(), .querySelectorAll(), getElementById(), getElementByTagName(), getElementByName(), getElementByClassName()

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

What is another way to add a text node to an element other than usingtextContent.

A

document.createTextNote(‘’) then appending it. InnerText takes out all whitespace. InnerHTML only shows whats visible.

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

How do you create a HTML element using vanilla Javascript?

A

Document.createElement(‘elementName’);

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

Why is using loops and arrays for creating multiple dom elements preferable to creating them one at a time?

A

It saves a lot of time. Not having to repeat yourself. And maybe loads a millisecond faster, no clue?

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

Why are arrays preferred over objects for the functionality referenced in question 1?

A

Because arrays have order? Arrays are indexed, so you can guarantee order. Objects might not get iterated in order.

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

Why is it important to be able to retrieve and use data from inputs?

A

It’s our communication path with our user. It allows them to interact with the site, and for our site to interact with their actions.

Good for to-do lists or creating notes or something. We can use that data to perform other events and modifications to the dom.

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

Why is it dangerous to assume you have the correct data when creating elements?

A

Just have to be careful to not mess up your webpage or something, especially if working off of data inputted by the user. If user inputs some sort of malicious code, and you use that code and create an element with it, it could be bad.

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

What is jQuery?

A

It is a library. It’s a JS file that you include in your web pages. It allows you to find elements using CSS-style selectors then do something with the elements using jQuery methods.

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

What is the jQuery selector function?

A

$() or jQuery().

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

What does the jQuery selector function return?

A

All elements that match? an Object?

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

Why would someone use jQuery over vanilla JavaScript?

A

Convenience of faster DOM traversal, and for property chaining. Core JS has everything that jQuery has.

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

What are some downsides from using jQuery over vanilla JavaScript?

A

It’s gonna die out eventually. It kind of departs from the actual original JS language. If you only get good at jQuery and always use it, then once jQuery dies out, you will be screwed.
Load time is also slower because it has to load it’s own JS page.

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

Why do we use thetag at the bottom of the body, instead of putting it inside the<head>tag?

A

Because there are changes to the DOM with JS, it will try to do them before the HTML has even loaded yet and not work.

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

How do you get the text out of an HTML element?

A

html() or text()

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

How do you get the value out of an HTML input field?

A

.val()

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

What’s the difference between.text()and.html()?

A

html grabs only from the first element matched, and also includeds all the markup. text grabs text from all matches and includes spaces, but no markup. Also does not include linebreak spaces.

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

What does.on()do?

A

it is like the eventlistener of jquery.

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

What is event bubbling?

A

When an event occurs on a target, and then goes up through through all of its ancestors.

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

What is the difference betweenevent.targetandevent.currentTarget.

A

event.target is the exact element clicked on, and currentTarget is where the bubbling ends. Example, if clicked a child of a div, it also means that that click happens on the parent div, and every ancestor element it’s in.
currentTarget is what you put your eventListener on, but the target is the most immediate thing that you interacted with.

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

What is the first argument the function setTimeout takes?

A

A function.

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

If the second argument is not passed into the setTimeout function, what is the default value?

A

1second

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

What are some scenarios where setTimeout can be useful?

A

Annoying paywall pop ups. Maybe to have something change or pop up when user scrolls down.

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

What does the setInterval function return?

A

the timer interval that is set as an argument in the setInterval() method.

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

What argument does the clearInterval function take?

A

the intervalID, which is the name of the variable used to store the setInterval() method

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

What are some scenarios where setInterval can be useful?

A

A timed quiz? A game? -Watch Vod

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

What is the event loop?

A

It’s the loop in which JS code is called and resolved in a certain order. It consists of the call stack, the webAPI’s and the callback queue.

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

What does the termblockingmean?

A

Code that is slow. When a thread is taking a long time to execute a callback (event loop) or a task (worker), then it is blocked. While a thread is

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

What is the call stack?

A

The queue and order in which code runs and resolves in JS. Functions get to the top of the stack when called, then popped off the top when there is a return.

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

Which elements in a website are useful to create dynamically?

A

Elements that are created due to user interaction. Google search, instagram posts, any sort of live feed, shopping carts.

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

Why should you not create all elements dynamically?

A

It can get very confusing trying to modify and make changes to html skeletons when they are all made with JS. You’d have to inspect your page in a browser and see what attributes it has and the structure, instead of being able to just easily see it in your html file.

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

What is a modal?

A

A sub window that can pop up and require interaction before returning to the main window. A scripted effect that allows you to overlay a small element over a website. A modal is a graphical control element subordinate to an application’s main window. It creates a mode that disables the main window but keeps it visible, with the modal window as a child window in front of it. Users are forced to interact with the modal window before returning to parent application.

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

What are some use cases for modals?

A
  • Ads, subscription requests, paywalls, errors, emergency states, amber alerts.
  • errors, warnings, data collection, confirm or prompt (remind to do something before moving on), helper (inform users of important information).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
101
Q

Why does a modal usually need to occupy the entire height and width of the viewport?

A

Or else users can interact to the main window behind it?

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

Give two examples of media features that you can query in an@mediarule.

A

max width, min width, min height, max height, color, grid, hover, aspect-ratio, monochrome, orientation, pointer, scan, update.

  • Nav list going from horizontal list to a hamburger button. Grid layouts. Changing a flex items’ flex-basis based on screen width. Basically any CSS Styling, like fonts, background-colors, background-images…
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
103
Q

Which HTML meta tag is used in mobile-responsive web pages?

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

Why do we need a single source of truth?

A
  • It is easier to keep track of what is being displayed and what data we store in one place, rather than having to cross reference a bunch of different files.
  • It makes changing this data and the DOM easier, when it’s all stored in one spot.
  • Consistency issues: DOM might be accurately reflecting the more up to date data in the JS data model.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
105
Q

Why would I create a function to generate my DOM Element instead of just writing my code in the global scope?

A

It’s easier to change something.

If you wanted to add another property to the data model, or a new object. It’s easy, since we have a reusable function that we use to just add it to the DOM.

Easier to modify the data model. Just add a new object then append the code.

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

What is a method?

A

A function that is a property of an object. They contain a set of instructions that together, represent one task.

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

What does a method do?

A

Runs a set of instructions on an object.

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

What isthis?

A
  • a keyword whose value changes based on where/when a function is called (at runtime). Generally it refers to the object to the left of the ‘.’. So like myObject.method, where method: function(){console.log(this)} would return myOjbect.
  • ‘this’ refers to the context where the function is being called, not where the function was defined. Is it always an object?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
109
Q

What does bind do?

A
  • Set’s the ‘this’ keyword to the provided value. Basically makes its so the ‘this’ keyword doesn’t have a dynamic nature in which it changes based on how the function is called and in which scope.
  • Kind of wraps a function up, so that ‘this’ will refer to the object argument we set, that the function/method appears in.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
110
Q

What is the difference between a function and an object literal?

A
  • Functions are objects.
  • for a function, the value of ‘this’ will change based on where its called? No clue. Are they the same thing?
  • An object literal can hold many functions inside of it and they all can be referenced and targeted easily like you would with any properties of an object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
111
Q

What is Prototypal Inheritance?

A

When creating an object, it inherits some usable methods from an object constructor (or prototype?), and that one has access to the methods from the the chained Object.prototype

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

What is the Prototypal Chain?

A

starts with your object that you made using a constructor, then it checks the constructor object, then the Object.prototype.

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

In the custom objects we created, I noticed that our prototype object has another__proto__property, where did that come from?

A

the Object.prototype?

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

Why does JavaScript have Prototypal Inheritance?

A

So we don’t have to define commonly used methods on every single object we make?

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

What does thenewkeyword do?

A
  • Creates a new instance of an object, based off an object constructor, that inherits all properties/methods from it.
    1. Creates a blank, plain JavaScript object;
    2. Links (sets the constructor of) this object to another object;
    3. Passes the newly created object fromStep 1as thethiscontext;
    4. Returnsthisif the function doesn’t return an object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
116
Q

I could’ve added a method to the constructor function by assigning a method to a property on the this object. Why do we have to add it to the prototype property?

A
  • So all future instances of the object constructor also have access to the method?? For inheritance.
  • Memory efficiency: so the method doesn’t have to live on every single new object created by a constructor. Those objects might not even use it. So by putting it to the prototype, we can just access it if we need it, and then doesn’t take up any more additional space by putting it on each new object instance.
  • Put tools on one higher level and the instanced objects can access the same one tool.
117
Q

What is the first thing that happens in a class when it is instantiated with thenewkeyword?

A

uzair answer: It calls the constructor function first, then sets all the properties for us with all the arguments we gave it, then finally returns the object to us as ‘this’

118
Q

Since classes are technically functions as well. Can you name a difference between classes and functions?

A
  • Classes are NOT hoisted. Functions ARE hoisted. So you can’t instantiate a new object BEFORE the class has been declared.
  • the body of a class is executed in strict mode. Aka code written here is subject to stricter syntax for increased performance. Otherwise silent errors will be thrown, and certain keywords are reserved for future version of ECMAScript.
119
Q

What is a static method?

A
  • a method that is available only on the instanced class/object??
  • Static methods have no access to data stored in specific objects.
  • A method that won’t be inherited by future instances of it (extends).
  • If a static method is on a constructor, then any extends or instances of the constructor won’t inherit that static method. You would have to user super to access it.
120
Q

What is the benefit of instantiating Classes within other classes?

A
  • It creates a connection between the Parent and all the children classes.
    • So it can access the methods on either.
  • It’s easy to see all the instantiated objects of a parent in one place??
121
Q

Why are parent - child relationships important in OOP?

A
  • By having a class inside another class, we have a connection between all the related things.
  • Everything is encapsulated under the hood of one object. And now all the classes inside of the parent can communicate to one another.
  • They reduce necessity to write identical code in each instantiated objected?
122
Q

What is the basic idea of OOP?

A
  • Main answer: Pairing data with functionality. Putting them in the same space.
  • Keeps all code organized and separated.
  • OOP is good for scaling. Not very effective for small applications.
  • Creating a template with useful methods and properties that can be used to create new objects without re-writing all of those methods and properties?
123
Q

Why did you have to bindthisfor thefeedChildmethod in theParentclass?

A

Because when feedChild gets run in the child object, it wouldn’t have access to the data in the parent object, namely the food.

124
Q

Why is it important to assigncallbackmethods to properties in theconstructor?

A
  • So that instantiated objects can access the methods? So parent’s can house all the utility methods and tools and children objects can just use them when needed.
  • So we can save the callback function for later use. Because after a function is run, it would just disappear. So we’re storing it in a property so if we want to use it again later, we have it.
125
Q

Why did theMakerclass require all of theParentclass info?

A

The instantiated parent wouldn’t have been able to access any of the data?

126
Q

Why did you have to bindthisfor thereplenishFoodmethod.

A
  • If we didn’t, then when replenishFood runs in the Parent object, ‘this’ would be the wrong object, and would not have access to the instantiated parent’s data like name, food, etc.
127
Q

What decides the order in which JS files must be loaded?

A
  • The files that depend on other files’ code in order to run, need to go later.
  • Files with code that have no dependency on any other file’s code, should go first.
128
Q

What is JSON?

A
  • A text-based data format following Javascript object syntax - MDN.
  • JSON’s exist as a string. Useful when you want to transmit data across a network. Though It needs to be converted to a native JS object when you want to access the data.
129
Q

What are serialization and deserialization and why are they useful?

A
  • the process of turning an object in memory in a stream of bytes so you can transfer them over a network or store them in a persistent storage. Deserialization is the opposite. Receiving a stream of bytes and turn them back into an object in the same state as it was before serialization.
  • It’s useful… because sending and receiving stuff takes less data?
  • It’s useful because we can send javascript objects over the network and have them come out the other end in the same format as before it is sent.
    • Because objects and their data are located all over, and we access them using memory address. If we just sent the memory address to another computer, the memory address would not be pointing to the right spot on their computer.
130
Q

How to you serialize data into a JSON string using JavaScript?

A

JSON.stringify()

131
Q

How do you deserialize a JSON string using JavaScript?

A

JSON.parse()

132
Q

What is a client?

A

A machine that makes a requests to a server for a service or resource.

  • A browser and terminal are things that can make requests.
  • Games, netflix, google maps, everything uses HTTP to make requests.
133
Q

What is a server?

A

A computer or something that provides a service or resource.

134
Q

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

A

GET or Connect?

135
Q

What are the formats of HTTP Requests and Responses?

A
  1. Astart-linedescribing the requests to be implemented, or its status of whether successful or a failure. This start-line is always a single line.
  2. An optional set ofHTTP headersspecifying the request, or describing the body included in the message.
  3. A blank line indicating all meta-information for the request hasbeen sent.
  4. An optionalbodycontaining data associated with the request (like content of an HTML form), or the document associated with a response. The presence of the body and its size is specified by the start-line and HTTP headers.
136
Q

How doesajaxwork?

A
  • performs an asynchronous HTTP (Ajax) request.

- It makes a request to a certain location, can get data from it, then does something on success or on error.

137
Q

Why did we need the jQuery CDN?

A

So we could use the $ sign, aka use jQuery methods, namely ajax()

138
Q

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

A

in the method property , in quotes.

139
Q

Why might you need to build elements dynamically with data from an AJAX request?

A

So you don’t have to store the data locally?

140
Q

Should you use named functions or anonymous functions for success and error handlers?

A

Named for the most part. It helps code readability and organization. Anonymous if its like 1 line of code or really simple I guess.

141
Q

Variables defined with thevarkeyword are function scoped.constandletare _____ scoped.

A

block - their scopes are always the innermost surrounding blocks

142
Q

Name some characteristics of a variable declared usingconst.

A

the binding (association between variable name and variable value) is immutable. However, the value itself may be unmutable. Like if you had const obj = {name: ‘hi’}, you could change the value of name property.

143
Q

Name some characteristics of a variable declared usinglet.

A

Variables declared with let are mutable. Kind of similar mechanics as var.

144
Q

What does block scope mean?

A

The area within a set of curly braces. Things outside can’t see inside, but things inside can see out.

145
Q

In the file we can push a new value to an array defined using theconstvariable. How does that work?

A

Not completely sure… Since it’s an object, the value of the const is a reference to that object. So you can make modifications to the object. The value of the const is just like a sign that points to the object in the memory space. If it’s a primitive data type, then nope, no way you can reassign that.

146
Q

Name some things thatvarcan do thatconstandletcan’t.

A

var is function scoped. so if a for loop is nested in a function, and you declare vars in the for loop, those vars are accessible outside of the for loop, within the function. Vars are hoisted. So they are undefined when access before they are declared. Let and const will throw a reference error you do that.

147
Q

Ifvarcan be used virtually anywhere, why would we switch?

A
  • Could cause more confusion when changing the value of a variable a lot and in different scopes??
  • using const and let signify meaning and intent in a clearer way? When you or someone else see’s const, then they know the variable wont be changing. So that means when you see let, then you know that it will be changing in the future.
  • Because hoisting was for noobs, and now were good enough to know when we need to use const and let.
148
Q

What is the syntax in writing a template literal?

A

${ } - note the backticks.

149
Q

What isstring interpolation?

A

if you put a dynamically computed value inside a ${ }, it is converted to a string and inserted into the string returned by the literal.

150
Q

When was destructuring introduced?

A
  • ES6
  • Because we needed a way to extract multiple values at once. We have a way to construct multiple properties or data at once, but we didn’t have a corresponding way to extract them.
151
Q

Why could the running commas technique of destructuring an array be a bad idea?

A

It’s ugly AF and in a long array, it will be very easy to miscount the commas and introduce some bugs.

152
Q

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

A

In destructuring, you have the destructuring target on the left, and the destructuring source on the right of the equal sign. The syntax looks reversed.

153
Q

How does an ES6 arrow function differ from an ES5 function?

A
  • With arrow functions the this keyword always represents the object that defined the arrow function.
  • arguments, super, this, and new.target are lexical in arrow functions, thus binding is not necessary. Arrow Functions can’t be used as a constructor, because normal functions support new via the internal method [[construct]] and the property prototype. Arrow functions have neither which is why new (() => {}) throws an error.
154
Q

When an arrow function’s code block is left without curly braces, what (if anything) changes in its functionality?

A

The right side of the arrow function is implicitly returned.

155
Q

In what situations would you possibly use an arrow function?

A

OOP. Don’t have to keep binding it?

156
Q

In what situations would younotwant to use an arrow function?

A
  • Don’t use them when just declaring a stand alone function. Or something with methods?
  • As callback functions. For when an object’s properties are methods/callbacks. When you want this to be binded. ???
157
Q

What is Array.prototype.filter useful for?

A

Having fine control over extracting specific data from an array.

158
Q

What is Array.prototype.map useful for?

A

Being able to modify an entire array and return the newly modified one.

159
Q

What is Array.prototype.reduce useful for?

A

It opens up like a whole new world in terms of doing work on an object/array and each of its elements. It’s like a for loop for objects?

160
Q

What is a CLI?

A

command line interface - use text to give commands

161
Q

What is a GUI?

A

graphical user interface - use graphics / pointers to give commands.

162
Q

Give at least one use case for each of the commands listed in this exercise.

A
  • man
    • man ls // displays manual page for the item (program) ls.
  • cat
    • concatenate files and print on the standard output.
    • cat laziness.txt // prints out the contents of the txt file in the command line.
    • in AWS we have command-line access to a computer, but not GUI. So this is important.
  • ls
    • Shows files of a directory (can be current or other folders if specified)
    • ls -aF lfz-staff // display ALL of the files in the lfz-staff folder (not the current folder) and show file indicators.
  • pwd
    • show the file path of the working directory.
  • echo
    • Print out a line of text.
    • echo 'Hello, World' > hello.txt
    • It’s like the console.log of the terminal.
  • touch
    • create an empty file. Can create files inside of directories other than working directory:
    • touch snoot/boop.txt
  • mkdir
    • make directories if they do not already exist.
  • mv
    • move (rename) files.
    • mv pokiemans pokemon
  • rm
    • remove a file. Cannot be undone without git.
    • rm lol.txt or rm -r my-folder/
  • cp
    • to copy a file into a new file
    • cp index.html index2.html
163
Q

What are the three virtues of a great programmer?

A
  1. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it.
  2. Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to.
  3. Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
164
Q

What is Node.js?

A
  • As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications
  • Node.js is a program that allows JavaScript to be run outside of a web browser. Node.js is powered by V8; the same JavaScript engine in the Google Chrome browser. It is free, open-source software and its source code is available on GitHub.
  • A back end language. It’s built with javascript and c++, and additional programs mixed into it to package it all up and stuff.
165
Q

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.

166
Q

What is a REPL?

A

read - eval - print loop. An interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user.

167
Q

When was Node.js created?

A

2009 by Ryan Dahl

168
Q

What back end languages have you heard of?

A
  • php, java, python, ruby, c#, Pascal, Pearl, Typescript (Deno), Visual Basic, C++, Rust
  • New cool hipster stuff: Go, Elixir, Elm
169
Q

What is a computer process?

A

process is the instance of a computer program that is being executed by one or many threads. 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

170
Q

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

A

Full stack Web development is based on making multiple processes work together to form one application, so having at least a cursory awareness of computer processes is necessary. This will be extremely important when learning about applications made of multiple components, such as clients, servers, and databases.

171
Q

What is theprocessobject in a Node.js program?

A

The process object is a global that provides information about, and control over, the current Node.js process. As a global, it is always available to Node.js applications without using require().

172
Q

How do you access theprocessobject in a Node.js program?

A

process

console.log(process)

173
Q

What is the data type ofprocess.argvin Node.js?

A

An array

174
Q

What is a JavaScript module?

A

A single .js file.

175
Q

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

A

exports, require, module, __filename, and __dirname ???

176
Q

Give two examples oftrulyglobal variables in a Node.js program.

A
setTimeout
setInterval
Class: Buffer
clearImmediate(immediateObject)
clearInterval(intervalObject)
claerTimeout(timeoutObject)
console
global
process
setImmediate(callback[, ...args])
setInterval(callback, delay[, ...args])
setTimeout(callback, delay[, ...args])
URL
URLSearchParams
WebAssembly
177
Q

What is the JavaScript Event Loop?

A

What is the JavaScript Event Loop?

178
Q

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

A

Blocking prevents any other code to run until that line of code finishes executing. Non-blocking code is added to the call stack and when run/parsed, will then move to the browser API’s column until the code finishes executing, then moves to the event queue, where it waits in line to be fully executed, once the call stack is done.

179
Q

What is a directory?

A
  • A folder in a storage medium.

- A file, whose job to point to other files.

180
Q

What is a relative file path?

A

a chain of local directories that lead to a file or another directory, in reference to your current directory location.

181
Q

What is an absolute file path?

A

the complete path to a file or directory, starting from the root folder.

182
Q

What module does Node.js include for manipulating the file system?

A

fs module.

183
Q

What is process.exit() ?

A
  • instructs node.js to terminate the process synchronously with an exit status of code. By default, exit code is 0. Diff exit codes have diff meanings. It’s basically like closing the node program with ctrl + c like i’ve been doing when I have infinite running counter.
  • if (err) throw err also does process.exit
184
Q

What method is available in the Node.jsfsmodule for writing data to a file?

A

writeFile(file, data, options, callback)

185
Q

Are file operations using thefsmodule synchronous or asynchronous?

A

There are both synchronous and asynchronous methods of us the fs module, but we will always be using the asynchronous way.

186
Q

How do you add a line break between your node command and the result??

A

‘\n’ like so:
fs.writeFile(‘note.txt’, note+ ‘\n’, err ⇒{})

So the + ‘\n’ just inserts a line break. Because when we do cat note.txt in node.js, it appears on the same line as the command we run, and it looks weird. So it just adds a line break.

187
Q

What is JSON?

A

Javascript Object Notation. A lightweight format for storing and transporting data. Used when data is sent from a server to a web page.

188
Q

What are serialization and deserialization?

A

Serialization is converting an object into a string format. When transmitting data or storing them into a file, data is required to be byte strings, but objects are usually not in this format. Serialization converts complex objects into byte strings. Deserialization is when after the data is transmitted, the data is convert from those byte strings back into the original object.

189
Q

Why are serialization and deserialization useful?

A

Because objects and their data are located all over, and we access them using memory address. If we just sent the memory address to another computer, the memory address would not be pointing to the right spot on their computer.

It’s useful because we can send javascript objects over the network and have them come out the other end in the same format as before it is sent.

190
Q

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

A

JSON.stringify()

191
Q

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

A

JSON.parse()

192
Q

What is a client?

A

A machine that makes a requests to a server for a service or resource.

  • A browser and terminal are things that can make requests.
  • Games, netflix, google maps, everything uses HTTP to make requests.
193
Q

What is a server?

A

A computer or something that provides a service or resource.

194
Q

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

A

GET Request

195
Q

What is on the first line of an HTTPrequestmessage?

A

A start-line describing the requests to be implemented or its status of whether successful or a failure.
composed of: method, request target, and protocol

196
Q

What is on the first line of an HTTPresponsemessage?

A

Status-line: the protocol version, a status code, and a status text that is purely informational to help humans understand the http message.

197
Q

What are HTTP headers?

A
  • A part of a request that alters the request to include certain parameters to tailor the response to what you need?
  • They define the operating parameters of an HTTP transaction.
198
Q

Is a body required for a valid HTTP message?

A

Body is optional.

199
Q

What is NPM?

A
  • The world’s largest software registry. You can use it to share and borrow packages, and many organizations use npm to mange private development as well.
  • It consists of 3 distinct components:
  • the website // used to discover packages, set up profiles and manage aspects of your npm experience.
  • the Command Line Interface (CLI) // runs from the terminal, and how most devs interact with NPM.
  • the registry // large public database of javascript software and the meta-info surrounding it.
200
Q

What is a package?

A
  • Bits of reusable code, often called modules.
  • It is a directory with files in it, and a file called package.json with meta data about this package.
  • General idea is that it is a small piece of that that solves one problem very well.
    • They are building blocks that you can use with many other packages.
201
Q

How can you create apackage.jsonwithnpm?

A

npm init —y or npm init -y for short.

202
Q

What is a dependency and how to you add one to a package?

A
  • A dependency is a package that is required to run a project.
  • You can add a dependency by just installing a package. like npm i jquery
  • You can add one by specificying it in package.json or through the command line
  • To add an entry to the"dependencies"attribute of apackage.jsonfile, on the command line, run the following command: npm install [--save-prod]
203
Q

What happens when you add a dependency to a package withnpm?

A

When installing the package, it will also install that dependency.

204
Q

How do you addexpressto your package dependencies?

A

npm i express

205
Q

What Express application method starts the server and binds it to a networkPORT?

A

listen(myPort) // app.listen(3000)

206
Q

How do you mount a middleware with an Express application?

A

app.use() and app.METHOD() functions, where METHOD is the HTTP method of the request that the middleware function handles (such as GET, PUT, or POST) in lowercase.

207
Q

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

request, response, and next (next middleware function in the stack / request-response cycle

208
Q

What is the purpose of the Content-Type header in HTTP request and response messages?

A

To tell the recipient (client or server) what the media type of the body is.

209
Q

What doesexpress.static()return?

A

A function named serveStatic (req, res, next) {}

210
Q

What is the local__dirnamevariable in a Node.js module?

A

An absolute path: the full system filepath leading up to the current directory where __dirname was run.

211
Q

What does thejoin()method of Node’spathmodule do?

A
  • concatenates the arguments to form a file path.

- Adds path segments together. c:/keenan/lfz/ + index.js

212
Q

What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?

A

application/json; charset=utf-8

213
Q

BODY is the same as DATA (the return of the ajax call) when you make an ajax call. So in an ajax call, when we do success: function (data) { console.log(data)},

A

That data is akin to the BODY, but BODY refers more specifically to post requests, and not get requests?

214
Q

What does the express.json() middleware do and when would you need it?

A

It parses incoming json body. Returns middleware that only parses JSON and only looks at requests where the content-type heacher matches the type option. Use it to turn a JSON into a normal JS object? So if someone does a post, it can turn it into an object we can manipulate in the back end?

215
Q

What is the significance of an HTTP request’s method?

A
  • It dictates what action our application will take, and therefore its response and what code to run.
  • indicate what you would like to have happen, but its up to the code that determines what happens.
216
Q

What is Webpack?

A

A module bundler used to bundle JS files for usage in a browser.

217
Q

How do you add adevDependencyto a package?

A
  • npm install [webpack-cli] –save-dev
  • To add an entry to the"dependencies"attribute of apackage.jsonfile, on the command line, run the following command:
  • npm install [--save-prod]
  • To add an entry to the"devDependencies"attribute of apackage.jsonfile, on the command line, run the following command:
  • npm install --save-dev
218
Q

What is an NPM script?

A
  • a way to bundle shell commands for a project. Instructions you would normally do in your command line in order to do something with your application.
  • They help automate repetitive tasks.
  • Makes sure everyone is using the same command with the same flags.
219
Q

How do you execute Webpack withnpm run?

A

npm run build

220
Q

How are ES Modules different from CommonJS modules?

A
  • Es Modules use the import and export keywords.
  • CommonJS uses require().
  • Es Module functionality is built into core JS
221
Q

What kind of modules can Webpack support?

A

commonJS, es6 modules, typescript, AMD, css file modules,

222
Q

What is React?

A
  • A JavaScript library for building user interfaces.
  • React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.
  • Declarative views make your code more predictable and easier to debug.
223
Q

What is a React element?

A

a plain object describing a component instance or DOM node and its desired properties. It contains the type (tag like h1 or div), a property (like color), and any child elements inside of it (like text).

A react element is NOT a DOM element. It is an element that we can use to DESCRIBE a DOM element we want to create.

224
Q

How do you mount a React element to the DOM?

A

ReactDOM.render(myReactElement, myDomTargetElement)

225
Q

Diff between a framework and a library

A
  • It’s a difference of control. We are in control of a library, but a framework is in control of us.
  • Library is like jQuery. We are giving the ‘$’ and we use it in all sorts of ways we want to.
  • But a framework does all of the function calling. We apparently never call the functions we use from a framework. We just pass things to it.
226
Q

What is Babel?

A

A javascript compiler. It’s a toolchain that is used to convert ECMAScript 2015+ code into backwards compatible versions of JS in current and older browsers or environments.

227
Q

What is a Plug-in?

A

A software component that adds a specific feature to an existing computer program. When a program supports plug-ins, it enables customization.

228
Q

What is a Webpack loader?

A
  • Transformations that are applied to the source code of a module. They allow yo uto pre-process files as you import or ‘load’ them.
  • They are kind of like ‘tasks’ in other build tools and provide a powerful way to handle front-end build steps.
  • Loaders can transform files from a different language (like TypeScript) to JavaScript or load inline images as data URLs. Loaders even allow you to do things like import CSS files directly from your JavaScript modules!
229
Q

How can you make Babel and Webpack work together?

A
  • When you run npm run build (aka when you compile your JS with webpack, it will also take Babel’s plugins into account and run their specific code as well? Pre-processing?
  • Install babel plugins and set them as devDependencies in package.json
230
Q

What is JSX?

A
  • A syntax extension that allows us to describe what the UI should look like, and allows us to write/read it in a familiar HTML format.
    • It it JS plus some stuff.
231
Q

Why must the React object be imported when authoring JSX in a module?

A

Since JSX compiles into calls to React.createElement, the React library must also always be in scope from your JSX code.

232
Q

How can you make Webpack and Babel work together to convert JSX into valid JavaScript?

A
  • By adding the babel plugins, webpack will compile all your modules and plugins so that when you write and run code, it will convert JSX into valid JS for you.
  • in the webpack.config.js we are telling it that if you see extensions of .js and .jsx, then run the babel plugin (@babel/plugin-transform-react-jsx).
233
Q

What is a React component?

A

Independent, reusable pieces of the UI. Conceptually, they are like JS functions. They accept arbitrary inputs (called ‘props’) and return React elements describing what should appear on the screen.

It’s a function. Can be a JS function or class. And it must return a react element. (clickme )

234
Q

How do you define a function component in React?

A
  • the function name MUST be capitalized. If it is not capitalized, react jsx plugin thinks it is an html element (tag).
  • Simplest way: create a javascript function.
  • ES6 Class way: create a class with a method on it that returns the react element.
235
Q

How do you mount a component to the DOM?

A

ReactDOM.render(, document.getElementById(‘root’));

236
Q

Why wrap a return in parenthesis?

A
  • return ( <div> click me! </div> )
  • It’s purely for readability beacuse it would look weird.
  • the tags wouldn’t line up like in html.
237
Q

What are props in React?

A
  • It’s an object containing key value pairs that are made from the attributes of a JSX component(?)/element(?).
  • In const element = ; // ‘name’ is a JSX attribute. ‘Sara’ is its value. This key value pair is stored within the props argument when passing it into a function component.
  • used for passing data from one component to another.
238
Q

How do you pass props to a component?

A
  • // these are not attributes, but key value pairs. Because this isn’t HTML.
  • You create a prop with an key and value on the react element.
239
Q

How do you write JavaScript expressions in JSX?

A

You write them like normal, just within curly braces.

240
Q

WhatArraymethod is commonly used to create a list of React elements?

A

map()

241
Q

What is the best value to use as a “key” prop when rendering lists?

A

A string that uniquely identifies a list item. Generally ID’s from your data.

242
Q

How do you create “class” component in React?

A

extends React.Component // class Welcome extends React.Component {}

243
Q

How do you access props in a class component?

A

this.props

244
Q

What is the purpose of state in React?

A
  • To store data that could be prone to change, and if it does change, trigger the render() method to update the DOM.
  • We just have one place that a component keeps track of one thing, one piece of data.
  • And if something happens to that piece of data, then render gets called again to change it based on the change.
  • Previously, we were triggering things with event listeners,
245
Q

How to you pass an event handler to a React element?

A

as a react element’s prop, onClick = {this.eventHandlerFunction}

246
Q

Why do we assign this.state an object?

A

In react, we always set the state as an object, because we can store more than one pieces of data on it.

247
Q

To know what a value of ‘this’ is, you CANNOT tell by the definition. You must be looking at the function call.

A

If there is no object to the left of the dot, it will be window. If there is an object left of the dot, it is that object.

248
Q

What is super()?

A

It is a javascript thing. It is effectively the constructor method of the thing we are extending from, so in this exercise, it is the .Component from React.Component.

249
Q

Why did we have to even use super()?

A

Because in handleClick(), setState() is a method that we did not even define, it is being inherited from the parent , React.Components (specifically Components).

250
Q

Why are there parenthesis around what looks like a code block? like in the pic?

A
  • It’s because anonymous arrow functions automatically return whatever is to the right of the arrow. And if there are brackets, that means that is just a code block for the arrow function (in which you have to manually use a return statement).
    • If you actually wanted to return an object, you have to put parenthesis around it to show that it is a javascript expression.
251
Q

What are controlled components?

A
  • Components in which React both renders the element, but also controls the state for that element and what happens in that element.
  • A react element in which the value of it is controlled by react, not the actual element ( like a form ).
  • Even if the user is typing into a input element on the DOM, the source of truth is the state of the component.
    • When the component is first mounted to the DOM, it has an initial state, set by the constructor.
    • In the exercise, we initially set email: ‘’.
    • Then the render() method runs, and the value is set to this.state.email, which is an empty string that we set.
      • So when that input renders, it renders as empty.
    • and the state gets changed by the method calls due to onChange, when we start typing or deleting.
    • When we type a letter, it updates the state, with setState, and it is very important to know that setState triggers the render() to happen again. Any time setState is called, render() occurs after.
    • So now the value get’s updated to the character you typed.
  • It’s kind of like, we’re re-rendering the element over and over each time there is a change in the input.
252
Q

What two props must you pass to an input for it to be “controlled”?

A

onChange and value

253
Q

What is PostgreSQL and what are some alternative relational databases?

A
  • Powerful, free, open source Relational Database Management System. The most advanced open source database of its kind, due to its robust feature set, standards compliance, and reliability.
  • Alternatives: MySql and SQL Server by Microsoft, and Oracle by Oracle Corporation.
254
Q

What are some advantages of learning a relational database?

A
  • They support good guarantees about data integrity. They store and modify data in a way that makes data corruption as unlikely as possible.
  • Developers ca nset up their database to reject “bad” data nd not worry about data being “half written”.
  • It is the most widely used type of database, so it is a very portable skill.
255
Q

What is one way to see if PostgreSQL is running?

A

running ‘top’ in another terminal and seeing if the process is active.

256
Q

What is a database schema?

A

A collection oftablesis called aschema. Aschemadefines how the data in a relational database should be organized. In relational databases, you typically have to define your schema up front and the database server will make sure that any data being written to the database conforms to that schema.

257
Q

What is a table?

A

Relational databases store data inrelations, commonly referred to astables.

258
Q

What is a row?

A
  • A data entry that contains columns or attributes. A table is made up of multiple rows that all contain the same columns/attributes.
  • For example. a row for a student might contain ‘firstName’, ‘lastName’, ‘dateOfBirth’ columns/attributes. And each subsequent row would have the same columns.
259
Q

What is SQL and how is it different from languages like JavaScript?

A
  • Structured Query Language
  • SQL is declarative like HTML and CSS in which you write what you would like to happen, and the browser interprets it and executes it in its own way.
  • Javascript is imperative, in which you tell JavaScript runtime what to do AND how to do it.
260
Q

How do you retrieve specific columns from a database table?

A
  • select keyword, then “nameOfColumn”

- select “firstName” from “someTable”

261
Q

How do you filter rows based on some specific criteria?

A
  • where “category” = ‘carbs’

- note that ‘carbs’ is in single quotes.

262
Q

What are the benefits of formatting your SQL?

A

It makes data retrieval and usage much easier to understand and read.

263
Q

What are four comparison operators that can be used in awhereclause?

A

< > = ≠

264
Q

How do you limit the number of rows returned in a result set?

A
  • limit #;

- Generally you put limit last.

265
Q

How do you retrieve all columns from a database table?

A

select *

266
Q

How do you control the sort order of a result set?

A
  • order by “category” desc

- By default, it orders by ascending order. So you don’t need to say it, but if you want descending order, use desc.

267
Q

How do you add a row to a SQL table?

A
  • insert into “tableName” (“column1”, “column2”)
    values (‘column1value’, ‘column2value’)
    • notice there are only single quotes on the values.
268
Q

What is a tuple?

A

A list of values ( kind of like an argument list)

269
Q

How do you add multiple rows to a SQL table at once?

A

insert into “tableName” (“column1”, “column2”)
values (‘column1value’, ‘column2value’),
(‘column1value2’, ‘column2value2’);

270
Q

How to you get back the row being inserted into a table without a separateselectstatement?

A
  • returning *;

- for specific columns: returning “productId”, “name”, “description”;

271
Q

How do you update rows in a database table?

A
  • update “tableName”
    set “column1” = ‘column1newValue’
  • where “productId” = 12;
272
Q

Why is it important to include awhereclause in yourupdatestatements?

A

Or else it will update for all rows.

273
Q

How do you delete rows from a database table?

A

delete from “myTable”

where “product” = ‘ShamWow’

274
Q

How do you accidentally delete all rows from a table?

A

when you don’t specify a ‘where’ clause

275
Q

What is a foreign key?

A
  • When a value of a column from one table is linked to a value of a column on another table.
  • This is done so we don’t have to put ALL the data from one table into another if we want to combine then. We can just link specifc parts with a foreign key.
276
Q

How do you join two SQL tables?

A
  • select * (or choose which columns - but I think * chooses all columns from BOTH tables)
    from “productsTable”
    join “suppliersTable” using (“suppliersTableColumn1”) // This links the two tables by their suppliersTableColumn1
277
Q

How do you temporarily rename columns or tables in a SQL statement?

A
  • column and table aliasing:column aliasing:
    jsx
      select "products"."name" as "product",
             "suppliers"."name" as "supplier"
        from "products"
        join "suppliers" using ("supplierId");
     
  • You can set aliases for the columns in the ‘select’ clause. This is to give better context or information about a column. Can also be used to resolve issues if two tables have the same name for a column.
  • table aliasing:

```jsx
select “p”.”name” as “product”,
“p”.”category”,
“s”.”name” as “supplier”,
“s”.”state”
from “products” as “p”
join “suppliers” as “s” using (“supplierId”)
where “p”.”category” = ‘cleaning’
and “p”.”price” < 20;
~~~

  • in the ‘from’ and ‘join’ clause, you can set an alias for the tables, so you can use those aliases in the select and save yourself from repetitive typing.
278
Q

What are some examples of aggregate functions?

A

count(), sum(), min(), every()

279
Q

What is the purpose of agroup byclause?

A

To get data and run aggregate functions on specific groups of rows instead of everything.

280
Q

Does order of the select and joins matter?

A

Order of the select from and the joins does NOT matter. As long as as the joins can make a link with the previous ‘join’ or ‘from’

281
Q

What are the three states a Promise can be in?

A
  • pending: initial state, neither fulfilled nor rejected.
  • fulfilled: meaning that the operation was completed successfully.
  • rejected: meaning that the operation failed.
282
Q

How do you handle the fulfillment of a Promise?

A

value ⇒ { fulfillment code block}

283
Q

How do you handle the rejection of a Promise?

A

reason ⇒ { console.error(reason.message) //reason code block}

284
Q

What doesfetch()return?

A

a promise object

285
Q

What is the default request method used byfetch()?

A

GET

286
Q

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

A

Pass in a second argument in the fetch method, which includes an object with request options, such as:
method, mode, cache, credentials, headers.

287
Q

When does React call a component’scomponentDidMountmethod?

A

At the end of of render() and after React updates the DOM and refs

288
Q

Name three React.Component lifecycle methods.

A

render(), constructor(props), componentDidMount(), componentWillUnmount(), componenDidUpdate()

289
Q

How do you pass data to a child component?

A
  • through this.state.users. In a then method call, I called this.setState to change the state to the parsed response from the fetch call.
  • You assign the state containing the data to a prop on a react element that is being created.