ES6/JSX/REACT Flashcards

1
Q

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

A

a lexical structure of source code which is grouped together. if, else, while, for loop, do while

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

What does block scope mean?

A

within the curly braces, the only place this thing would exist

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

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

A

block scoped

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

What is the difference between let and const?

A

let can be reassgined and const can not

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

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

A

if the const object is an object or array its properties or items can be updated or removed but not reassigned

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

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

A

every thing should be a const, until you have a variable that will be reassigned.

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

What is the syntax for writing a template literal?

A

wrap your text in backticks and for substitution we use ${}

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

What is “string interpolation”?

A

when you substitute part of the string for the values of variables or expressions.

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

What is destructuring, conceptually?

A

Its something that allows us to access properties inside of an object or indexes inside an array, and then store that information into a new variable

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

What is the syntax for Object destructuring?

A

const{ property1: variable1} = object;

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

What is the syntax for Array destructuring?

A

const foo = [“one”, “two”, “three”];

const [red, yellow, green] = foo;
console.log(red); // “one”
console.log(yellow); // “two”
console.log(green); // “three”

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

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

A

The difference is if the curly braces is on the left side, it is object/array destructuring and if its on the right side, we’re creating a new object.

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

What is the syntax for defining an arrow function?

A

const add = (x, y) => { return x + y; };
const sample = x => {}
const sample = ()=>2+2

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

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

A

implicit “return”. The braces can only be omitted if the function directly returns an expression.
const add = (x, y) => { x + y; };
Nao ia dar certo pq com o {}, nao tem mais o implicit return

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

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

A

its going to be based on lexical this.
an arrow function captures the this value of the enclosing context instead of creating its own this context.

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

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

How do you handle the fulfillment of a Promise?

A

promise1.then((value) => {
console.log(value);
});

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

What is Array.prototype.filter useful for?

A

To return a new array with all the elements that pass the test implemented by the callback() function.

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

What is Array.prototype.map useful for?

A

Array.map() method allows you to iterate over a new array and modify its elements using a callback function.

For each does the same thing as .map() but the difference is that it does not return a new array

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

What is Array.prototype.reduce useful for?

A

The array reduce in JavaScript is a method used to reduce an array to a single value by passing a callback function on each element of the array.

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

What is “syntactic sugar”?

A

syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express

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

Describe ES6 class syntax.

A

class Person {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
}
let john = new Person(“John Doe”);
let name = john.getName();
console.log(name); // “John Doe”

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

What is “refactoring”?

A

code refactoring is the process of restructuring existing code without changing its external behavior.

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

What is Webpack?

A

Its a program that allows us to take all of our script files and combine them into one file

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

How do you add a devDependency to a package?

A

npm install <package-name> --save-dev</package-name>

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

What is an NPM script?

A

It allows us to run different commands. ex: build: webpack

28
Q

How do you execute Webpack with npm run?

A

npm run build

29
Q

How are ES Modules different from CommonJS modules?

A

With CommonJS, all of the dependencies for a project are stored in one file called node_modules/. With ES modules, each dependency is stored in its files. This allows developers to better control how their dependencies are used and makes it easier to version software. ES6 greater functionality. Require its for entire file, takes more time to load.
Common JS: require method
ES Module: export/import

30
Q

What kind of modules can Webpack support?

A

ECMAScript modules
CommonJS modules
AMD modules
Assets
WebAssembly modules

31
Q

What is React?

A

A JavaScript library for building user interfaces

32
Q

What is a React element?

A

it is an object representation of a virtual DOM node.

33
Q

How do you mount a React element to the DOM?

A

create a root (createRoot()) and then use the render method. render-> where we want to append to

34
Q

What is a Plug-in?

A

a plug-in (or plugin, add-in, addin, add-on, or addon) is a software component that adds a specific feature to an existing computer program. When a program supports plug-ins, it enables customization. ex: mp3 file, web video

35
Q

What is a Webpack loader?

A

Loaders are transformations that are applied to the source code of a module. It allows us to pre process files before you implement them.
Loaders can transform files from a different language (like TypeScript) to JavaScript or load inline images as data URLs.

36
Q

How can you make Babel and Webpack work together?

A

install the module under dev dependency and have the webpack.config.js

37
Q

What is webpack.config.js?

A

gives us the option of configuring how webpack interacts with other packages that we have installed in the application. ex: babel loader

38
Q

What is JSX?

A

it is a syntax extension to JavaScript. It allows you to write HTML elements inside of a JS file. Its not react but react uses it.

39
Q

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

A

The jsx code won’t work if you dont import it because of that react create element method. If we go to the main.js file, on the bottom, we’ll see createElement method with the html elements being created. And we need react because we’re using in the method.

40
Q

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

A

use the @babel/plugin-transform-react-jsx

41
Q

What is a React component?

A

Components are like JavaScript functions that let you split the UI into independent, reusable pieces, and think about each piece in isolation. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

42
Q

How do you define a function component in React?

A

a JavaScript function that accepts a single “props” (which stands for properties) object argument with data and returns a jsx and then we append it to the root.

43
Q

How do you mount a component to the DOM?

A

You use render method on the root

44
Q

What are props in React?

A

a type of object where the value of the attribute of a tag is stored/
“props” (which stands for properties) object argument with data. ex: <CustomButton text=”I”>

45
Q

How do you pass props to a component?

A

pass them as the argument to the function. and we do that as an attribute of the function call.

46
Q

How do you write JavaScript expressions in JSX?

A

You can put any valid JavaScript expression inside the curly braces in JSX.
ex: return{ <button>{props.text}</button>}

47
Q

How do you create “class” component in React?

A

class className extends React.Component{ render() {return }}. ex class Animal{} class Bird extends Animal{} -> now the class bird will have access to the methods inside the class Animal

48
Q

How do you access props in a class component?

A

{this.props.name}

49
Q

What is super()?

A

super is calling the constructor from where we’re extending and access all the method and information that is inside the constructor that we are extending from/ super is calling the constructor for the class we’re extending from

50
Q

What is the purpose of state in React?

A

The state is a built-in React object that is used to contain data or information about the component and is only available within that component.

51
Q

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

A

eventName = {functionName}. ex: onClick={this.handleClick}

52
Q

What are controlled components?

A

A controlled component is a component that renders form elements and controls them by keeping the form data in the component’s state. In a controlled component, the form element’s data is handled by the React component (not DOM) and kept in the component’s state.

53
Q

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

A

A controlled input accepts its current value as a prop, as well as a callback to change that value. ex: value and onChange

54
Q

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

A

map(). because it returns an array so we can loop through it.

55
Q

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

A

Most often you would use IDs from your data as keys

56
Q

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

A

Most often you would use IDs from your data as keys

57
Q

What does express.static() return?

A

Returns a path/middleware
The function determines the file to serve by combining req.url with the provided root directory. When a file is not found, instead of sending a 404 response, it calls next() to move on to the next middleware, allowing for stacking and fall-backs.

58
Q

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

A

The directory name of the current module

59
Q

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

A

Combines any number of paths/directories. joines them and normalizes them.
Ex:
const publicPath = path.join(__dirname, ‘public’) -> dirname is relative to the computer I am specifically using. ‘public’ folder is the one to serve from.

60
Q

What does fetch() return?

A

a promise which is fulfilled once the response is available.

61
Q

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

A

The default method of fetch() is GET. If needed, we can also make a POST, PUT and DELETE method request as well.

62
Q

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

A

put in the second arg, an object
ex: fetch(resource, options) -> options is an object

63
Q

When does React call a component’s componentDidMount method?

A

immediately after a component is mounted (inserted into the tree).

64
Q

Name three React.Component lifecycle methods.

A

componentDidUpdate() , componentWillUnmount() , and componentDidMount()

65
Q

How do you pass data to a child component?

A

Using props