JavaScript ES6 Flashcards

1
Q

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

A

A code block refers to the code within the curly braces.

Examples of code blocks include functions, loops, and conditionals.

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

What does block scope mean?

A

Block scope defines the availability of a variable to only within it’s code 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 withconstorlet?

A

Block scope

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

What is the difference betweenletandconst?

A

let can be reassigned

const cannot be reassigned

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 aconstvariable that points to anArray?

A

Pushing is changing the value to the array in memory space, but not reassigning the reference value.

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

Prefer const, unless a variable needs to be mutated.

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

Back ticks start and end `` with any variables starting with dollar sign wrapped in curly braces.

Hello ${name}!

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

What is “string interpolation”?

A

The ability to 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

Assignment of javascript object properties to variables

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

What is the syntax forObjectdestructuring?

A
Variable declaration
Curly brace with variable(s) 
*If renaming propertyname : new name*
Assignment Operator
Object to destructure

e.g.
let { firstName, lastName } = person;

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

What is the syntax forArraydestructuring?

A

Variable declaration
Square Bracket with variable(s)
Assignment Operator
Array to destructure

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 creatingObject/Arrayliterals?

A

Destructuring will have the variables in brackets or curly braces on the left side of the assignment operator, and an existing array or object on the right hand side

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
  • Variable keyword
  • Variable name
  • Parameters
  • Arrow
  • Bracket (Only required if 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
  • The function can only have one line of code

- The code block must be an expression (code that resolves to value)

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

How is the value ofthisdetermined within an arrow function?

A
  • The value of this is determined by it’s parent code block (outward with arrow functions)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When is it necessary to have parenthesis for parameters?

A
  • 0 or 2+ mandatory

- 1 not mandatory

17
Q

What are the three states a Promise can be in?

A
  • Pending: initial state, neither fulfilled nor rejected
  • Fulfilled: Successul operation
  • Rejected: Failed operation
18
Q

How do you handle the fulfillment of a Promise?

A
  • then() method attaches fulfillment and rejection handlers to the promise, and returns a new promise
19
Q

How do you handle the rejection of a Promise?

A
  • catch() method appends a rejection handler
20
Q

What isArray.prototype.filteruseful for?

A

Returning a filtered array

21
Q

What isArray.prototype.mapuseful for?

A

Creating a new array with all of the previous arrays elements modified

22
Q

What isArray.prototype.reduceuseful for?

A

Returning the sum of an array

23
Q

What is “syntactic sugar”?

A

An alternative style on an existing syntax to make the language more clear for human use.

24
Q

What is thetypeofan ES6 class?

A

Function

25
Q

Describe ES6 class syntax.

A
class Example
   constructor(a, b, c) {
      this.a = a
      this.b = b
      this.c = c
   },
methodName() {}
26
Q

What is “refactoring”?

A

Restructuring existing code without changing its external behavior.

27
Q

What is Webpack?

A

Webpackis astatic module bundlerfor modern JavaScript applications

28
Q

How do you add adevDependencyto a package?

A

npm install –save-dev [package name]

29
Q

What is an NPM script?

A
  • Commands that would typically be entered in command line to perform an action with your project
  • NPM script is stored within your package.json file under “scripts”
30
Q

How do you execute Webpack withnpm run?

A

In package.json add to scripts:
“build”: “web pack”

npm run build

31
Q

How are ES Modules different from CommonJS modules?

A

ESM is statically analyzable, which allows for tree shaking (process that removes unused code from bundles)

Enhanced syntax (import export vs require)

ESM is official

32
Q

What kind of modules can Webpack support?

A

ECMAScript Modules
CommonJS Modules
AMD modules

33
Q

What doesfetch()return?

A

APromisethat resolves to aResponseobject.

34
Q

What is the default request method used byfetch()?

A

GET

35
Q

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

A

Using request options, as a second argument with a specified method.

36
Q

What must the return value of myFunction be if this expression is possible:

myFunction()();

A

myFunction calls a function and that inner function executes immediately after

Therefore, myFunction’s return must be a function

37
Q

What does this code do?

const wrap = value => () => value;

A

Returns a value

38
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

Upon definition

39
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

A closure