Module 3 Flashcards

1
Q

What is Array.prototype.filter useful for?

A

It helps create a new array with elements of the array matching specified parameters, which lets you search for specific elements.

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

It is useful for making changes to all elements of an existing array and assigning it to a new array, without actually modifying the original array.

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

What is Array.prototype.reduce useful for?

A

To combine bunch of data using a defined function into one result

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

What is “syntactic sugar”?

A

Syntax in a programming language that is designed to be easier to read by humans

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

Describe ES6 class syntax.

A

Declare class ClassName { constructor( ) { } method( ) { } }

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

What is “refactoring”?

A

Restructuring code without changing its behavior

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

Does a class need constructor within?

A

No

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

What is Webpack?

A

Module bundler, takes files and groups into one file

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

What is an NPM script?

A

A way to write common commands in a short way rather than typing out the whole thing. Typically stored in package.json, takes a saved command and executes for you.

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

How are ES Modules different from CommonJS modules?

A

Syntax differences, ESM can use the import and export keywords, are more compact since it is built in.

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

What kind of modules can Webpack support?

A

ES modules, commonJS modules, nearly every JS module.

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

What is React?

A

A js library for building user interfaces, it is a javaScript framework for building webpages. Makes setting up a webpage easier than direct dom manipulation.

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

What is a React element?

A

A dom element created by react

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

How do you mount a React element to the DOM?

A

You use React.createElement( );

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

What is Babel?

A

A toolchain that converts ES6 script into backwards compatible JS. Can also convert JSX

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

What is a Plug-in?

A

A software addon component that adds a specific feature to an existing computer program

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

What is a Webpack loader?

A

A transformation that is applied to source code to transform files from different languages into JS or load inline images as data URLs

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

How can you make Babel and Webpack work together?

A

Using Babel Loader, it works such that webpack reads the files, passes it through babel to convert, then gets a converted language back to package.

20
Q

What is JSX?

A

A html-like markup language that can be used with JavaScript and React. But note it is neither HTML nor JavaScript.

21
Q

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

A

JSX cannot be read by browsers by default, need to be converted. Babel converts JSX to React.createElement(‘tag’, props, ‘textContent’)

22
Q

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

A

Use babel loader to connect babel to webpack then the plugin @babel/plugin-transform-react-jsx

23
Q

What is a React component?

A

They split a ui into independent reusable pieces.

24
Q

How do you define a function component in React?

A

Any javaScript function that takes one argument props and returns a React element

25
Q

How do you mount a component to the DOM?

A

Use ReactDom.render( component, DomPath )

26
Q

What are props in React?

A

Arbitrary read-only inputs accepted by a React component. They are how information is passed from outside a component into a component.

27
Q

How do you pass props to a component?

A

Use the component and assign the key-value pair to the component. Like assigning attributes to html tags. Not actual attribute, don’t call them that.

28
Q

How do you write JavaScript expressions in JSX?

A

They have to be enclosed in { } braces.

29
Q

How do you create “class” component in React?

A

Use class CustomComponent extends React.component{ render() { jsx } }. The only thing required is render(), constructor is not necessary.

30
Q

How do you access props in a class component?

A

this.props.propName because props becomes a property of the class.

31
Q

What is the purpose of state in React?

A

Allows you to save certain property value changes to change component output.

32
Q

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

A

You have to include it as a key-value property pair (or jsx attribute) to its component after defining it as a method in its class

33
Q

What are controlled components?

A

An input element whose value is controlled by react

34
Q

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

A

value and onChange.

35
Q

What Array method is commonly used to create a list of React elements?

A

array.map( )

36
Q

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

A

Unique id values, if possible. Second best is index number.

37
Q

What does express.static() return?

A

It returns a function (to be used by app.use( ) )

38
Q

What is the local __dirname variable in a Node.js module?

A

The current absolute path of the current module.

39
Q

What does the join() method of Node’s path module do?

A

Joins multiple directory names into one direct path.

40
Q

What does fetch() return?

A

Returns a promise, this is async so it does not block other JS code. Promise fulfilled = response received that needs to be converted.

41
Q

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

A

GET

42
Q

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

A

Use an init object. To use another method example:

fetch(‘link’, { method: ‘POST’ })

43
Q

When does React call a component’s componentDidMount method?

A

After a component is added to DOM tree. Basically, after the first render method is called.

44
Q

Name three React.Component lifecycle methods.

A

constructor, render, componentDidMount, componentDidUpdate, componentWillUnmount. Technically setState is also a lifetycle method.

45
Q

How do you pass data to a child component?

A

As props

46
Q

How do you get the HTTP request header?

A

with req.get(headerName)

47
Q

what is .next()?

A

next() is just the third argument passed to the express middleware function and can be named anything, but conventionally named "next" to avoid confusion.