Senior JavaScript Flashcards

1
Q

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

A

Code blocks are denoted by curly braces, where we can have multiple statements.
- if…else, for, while statements

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

What does block scope mean?

A

Area within if, switch conditions or for and while loops.

- Functions are function scoped

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 Scoped

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

What is the difference betweenletandconst?

A

You can’t change the value of const once declared.

  • Can’t be reassigned or you will get a TypeError
  • const RED; doesn’t work because it must be assigned a value (read-only)
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
  1. Constants cannot be changed through re-assignment nor can they be redeclared
  2. For arrays we are just just adding to the “list”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do we “freeze” values in an object

A

Object.freeze() to make it immutable.

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

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

A

If the value of the variable is not changing, use const.

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

What is the syntax for writing a template literal?

A

Instead of using single or double quotes, use backticks around the whole expression

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

What is “string interpolation”?

A

Substituting parts of the string for values of variables or expressions

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

What is destructuring, conceptually?

A

Makes it possible to unpack values from arrays, or properties from objects, into distinct variables

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

What is the syntax forObjectdestructuring?

A

What is the syntax forArraydestructuring?

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