es6 Flashcards

1
Q

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

A

Code blocks are chunks of code within two curly brackets { }

Many things use { }, such as loops, if else statements, etc

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

What does block scope mean?

A

The value exists within the scope of the code block

Afterward, the value is returned to its original value

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 allows you to change the value of a variable within a code block

const keeps the value and the it can never be changed
Unless it is referring to properties inside of an object

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

You can edit the items inside a const array. But the object itself, can never not be an array

We are not changing the name binding. We are not changing where the items points

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

const should be used for items that will not be edited later

let is used when you know you will be changing the value of an item later on

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

const bio = My name is ${firstName} ${lastName} and I am ${age} years old.;

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

What is “string interpolation”?

A

Defining a string using template literal and plugging in javascript expressions ( ${ } )

The ability to embed variables and expressions into a string you would concatenated

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

What is destructuring, conceptually?

A

Being able to pull the values of an object or array, in such a way that would now require us to refer to the data’s container later on.

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
First you have the object literal:
const book1 = {
      title: 'Goodnight Punpun',
      author: 'Inio Asano',
      libraryID: 3353
    };

Then you can deconstruct the object:
const { title, author, libraryID } = book1;

You can now use the values freely:
console.log(The title of this book is ${title}, the author is ${author}, and the library id is ${libraryID});

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
You have your regular array:
const numbers = ['one', 'two', 'three', 'four'];

You deconstruct it:
const [first, second, …remainder] = numbers;

Use each of those elements freely:

console. log(first); // “one”
console. log(second); // “two”
console. log(remainder); //this will console [“three”, “four”]

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

When creating objects/arrays, the name of the object is on the left side of the = sign:

const book1 = {title: 'Goodnight Punpun', author: 'Inio Asano', libraryID: 335 };
const numbers = ['one', 'two', 'three', 'four'];

When deconstructing them, the properties or list are on the left side of the = sign:

const { title, author, libraryID } = book1;
const [first, second, …remainder] = numbers;

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

let functionName = (argument1, argumentN) => { return stuff; }

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

Leaving out the curly braces, means you have an implied “return”

As soon as you include curly braces, you need to add “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

The value of THIS is determined at definition time, not call time

In other words, it doesn’t have it’s own THIS, but gets the THIS location of the function it is being called from (aka the object containing the method, which uses the method)

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