ECMA Script 6 (ES6) Flashcards

1
Q

What happens when you re-declare a variable defined with let?

A

You get an error

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

What is one of the more common problems with the var keyword?

A

You can re-declare variables without receiving an error.

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

What is the difference in scope between variables declared with var and let?

A

When you declare a variable with the var keyword, it is declared globally, or locally if declared inside a function.

The let keyword behaves similarly, but with some extra features. When you declare a variable with the let keyword inside a block, statement, or expression, its scope is limited to that block, statement, or expression.

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

What’s the difference between declaring variables with let and const?

A

const variables are read only.

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

What does the const keyword prevent?

A

Using the const declaration only prevents reassignment of the variable identifier.

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

What type of objects assigned using const are mutable?

A

Arrays and Objects - it only prevents reassignment.

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

When using a const declaration, how do you prevent your object from being changed?

A

Object.freeze()

Once the object is frozen, you can no longer add, update, or delete properties from it. Any attempt at changing the object will be rejected without an error.

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

How do you write anonymous functions in ES6?

A

you can use arrow function syntax:

const myFunc = () => {
  const myVar = "value";
  return myVar;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you write an anonymous function with no function body in ES6?

A

const myFunc = () => “value”;

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

What’s the syntax for default parameters?

A

const greeting = (name = “Anonymous”) => “Hello “ + name;

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

How do you pass a variable number of arguments to function?

A

ES6 introduces the rest parameter for function parameters. With the rest parameter, you can create functions that take a variable number of arguments. These arguments are stored in an array that can be accessed later from inside the function.

Check out this code:

function howMany(...args) {
  return "You have passed " + args.length + " arguments.";
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly