Module 3 Flashcards

1
Q

What is Array.prototype.filter useful for?

A

to filter data from an array and assign it to a new array

loops through the array and checks for truthies and falsies

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

What is Array.prototype.map useful for?

A

for data transformations
can transform data and create a new array for that
loops through the array and the return value of each iteration is pushed to new array

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

What is “syntactic sugar”?

A

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

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

What is the typeof an ES6 class?

A

function

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

Describe ES6 class syntax.

A
class Person {
    constructor(name) {
        this.name = name;
    }
    getName() {
        return this.name;
    }
}
Code language: JavaScript (javascript)'

use the class keyword with name and convention to start with uppercase letter and then everything lives inside the class block including your constructor method and any other method definitions

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

What is “refactoring”?

A

rewriting code to make it more beautiful /readable

not changing any of the functionality

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

What is Array.prototype.reduce useful for?

A

takes an array and reduces it down to a single value

taking values of an array and turning it into an object

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

What is Webpack?

A
Webpack is a free and open-source module bundler for JavaScript
lets us write modules and supports any module formats because it helps us to bundle many js files into 1 js file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you add a devDependency to a package?

A

npm install some-package –save-dev (can also put the package name at the end)

npm i -D some-package (= shortcut)
i short for install, D short for save dev

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

What is an NPM script?

A

The “scripts” property of your package.json file that can be executed by running npm run-script or npm run for short.

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

How do you execute Webpack with npm run?

A

ensuring to include “build”: “webpack” in your NPM script

execute whatever script executes webpack

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

How are ES Modules different from CommonJS modules?

A

SYNTAX is easier to read with import/exporting
(import statements vs require statements)
Their syntax is even more compact than CommonJS’s.
Their structure can be statically analyzed (for static checking, optimization, etc.).
Their support for cyclic dependencies is better than CommonJS’s.

CommonJS is built in node js and designed for synchronous loading

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

What kind of modules can Webpack support?

A
  1. ECMAScript modules
  2. CommonJS modules
  3. AMD modules

supports BOTH ES modules and CommonJS modules
stick with require statements in node & import statements in front end code

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

What is React?

A

a JS library for building interfaces

that is declarative and component-based

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

What is a React element?

A

it’s a symbol?
Symbol(react.element)
they are immutable

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

How do you mount a React element to the DOM?

A

create a root by using ReactDOM.createRoot(container) & assigning that value to a root variable
and then root.render(element)

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

What is Babel?

A

a solution for allowing browsers to use complex / modern JS that is not fully supported across various browsers (JSX, typescript)

its a JS compiler built on a plug in system that parses JS syntax into an abstract syntax tree and rewrites it into a version that can be interpreted by your browser

Js compiler that takes ES6 and converts it to ES5

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

What is a Plug-in?

A

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

Babels plug-ins are needed to do anything
presets are dynamic bundles based on years
there is a preset for react

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

What is a Webpack loader?

A

allows you to pre-process your files

20
Q

How can you make Babel and Webpack work together?

21
Q

What is a React component?

A

returns a react element

22
Q

How do you define a function component in React?

A

like a function that accepts single “props” object argument and it returns a react element

23
Q

How do you mount a component to the DOM?

A

call the component

24
Q

What is a React component?

A

describes a reusable piece of the UI

25
How do you define a function component in React?
like a function that accepts single "props" object argument and it returns a react element (JSX) name HAS to start with a capital letter to use it we write it as JSX & they are reusable
26
How do you mount a component to the DOM?
root.render(element) | element = component function return value
27
What are props in React?
parameters in React component functions via attribute like syntax way that we pass data into our components
28
How do you pass props to a component?
define them in the JSX with with key value pairs that looks like an attribute like syntax
29
How do you write JavaScript expressions in JSX?
{ JS expression }
30
How do you create "class" component in React?
``` class Class extends React.component { render ( ) { return } } ``` class extending the component property of React
31
How do you access props in a class component?
this.props
32
What is the purpose of state in React?
so the component renders something different depending on the state allows us to re-render a component with some kind of different outcome
33
How to you pass an event handler to a React element?
on the JSX element in curly braces & the callback is a property on the this object add event directly on the element we want it on & pass it a method or a function to be called when that event happens i.e. Click ME!
34
What are controlled components?
technique that allows you to access the form data that user enters into the form via the react this.state forces your user input to override the react this.state so that you can access the data in this.state input controlled by component state
35
What two props must you pass to an input for it to be "controlled"?
value and onChange (which is an eventlistener) (and name)
36
What Array method is commonly used to create a list of React elements?
.map()
37
What is the best value to use as a "key" prop when rendering lists?
IDs | anything uniquely identifying to each object
38
What does express.static() return?
serveStatic function - a callback function that you can mount in your app.use() in order to access the files in the specified directory function
39
What is the local __dirname variable in a Node.js module?
The directory name of the current module
40
What does the join() method of Node's path module do?
joins path names together
41
What does fetch() return?
a promise | when promise resolves it returns the response object
42
How do you specify the request method (GET, POST, etc.) when calling fetch?
``` const myInit = { method: 'GET', headers: myHeaders, mode: 'cors', cache: 'default', }; ```
43
How do you specify the request method (GET, POST, etc.) when calling fetch?
``` const myInit = { method: 'GET', headers: myHeaders, mode: 'cors', cache: 'default', }; ```
44
When does React call a component's componentDidMount method?
immediately after the component is mounted | after render is called for the first time
45
Name three React.Component lifecycle methods.
render() constructor() setState() ^they are also technically considered lifecycle methods 1. componentDidMount() - gets called right after first render 2. componentDidUpdate() - is given previous state & previous props. If state changes, this will be called once it has already been changed 3. componentWillUnmount() - called right before the component is removed from the DOM
46
How do you pass data to a child component?
pass data via props