ES6 JS Flashcards

1
Q

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

A

The code block is a location where we write codes between the curly braces.
{}

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

What does block scope mean?

A

It restricts the variable that is declared inside the specific block from being accessed from outside of the block

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

blocked-scope

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

You can change the value assigned to the let keyword while const you cannot.

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

Because you are not reassigning a different array to the const variable, you are simply adding a value to the same array
The object is still mutable when it’s assigned to a variable so you can add data to it

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

If you need to reassign values to the variable, then you should use let

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

${variable}

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

What is “string interpolation”?

A

ability to substitute part of the string for the values of variables or expressions
substitute a variable with a string

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

What is destructuring, conceptually?

A

JS expression that makes it possible to unpack elements from arrays or properties from objects, into distinct variables

It’s how you get object properties or array elements into one line

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

let { property1: variable1, property2: variable2 } = 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

let [x, y, z] = variableName

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

you have the variable name to the left of the ‘=’ operator when creating object/array literals. Whereas, the variable name is on the right when destructuring.

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

parameter => expression
param => { statement }

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

It has an implicit return
You will need a curly braces when you have multiple lines of statement with a return statement

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

parent’s code block and is being determined at definition time

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

What is a CLI?

A

Command-line interface
to receive commands from a user in the form of lines of text

17
Q

What is a GUI?

A

Graphical user interface
For users to interact with graphical icons

18
Q

Give at least one use case for each of the commands listed in this exercise.
man, cat, ls, pwd, echo, touch, mkdir , mv, rm, cp

A

man - interface to the system reference manuals
cat - concatenate files and print on the standard output
ls - list directory contents
pwd - print name of current/working directory
echo - display a line of text
touch - change file timestamps
mkdir - make directories
mv – move (rename) files
rm - remove files or directories
cp - copy files and directories

19
Q

What are the three states a Promise can be in?

A

pending, fulfilled, or rejected

20
Q

How do you handle the fulfillment of a Promise?

A

.then() - pass in callback function
When the promise is fulfilled, this code is used to execute the function

21
Q

How do you handle the rejection of a Promise?

A

.catch() - pass in a callback function, if the promise is rejected, this code will be executed

22
Q

What is Array.prototype.filter useful for?

A

It creates a new array filled with elements that pass a test provided by a function

23
Q

What is Array.prototype.map useful for?

A

you can format it into a string

24
Q

What is Array.prototype.reduce useful for?

A

we can use it to turn the array into an object
return a single value from an array

25
Q

What is “syntactic sugar”?

A

That allows code to become easier to read or friendly but at the cost of flexibility

26
Q

What is the typeof an ES6 class?

A

object

27
Q

Describe ES6 class syntax.

A

class ClassName {
constructor(param) {
// stuff
}
methodName(param) {
// more stuff
}
}

28
Q

What is “refactoring”?

A

Process of restructuring existing computer code without changing its functionality

29
Q

How are ES Modules different from CommonJS modules?

A

each dependency is stored in its file for ES Modules. This allows developers to better control how their dependencies are used. Whereas, CommonJS keeps all the files in one file named node_modules

ES6 has a greater functionality attached to it

30
Q

What kind of modules can Webpack support?

A

ESMAScript modules
CommonJS modules
amd MODULES