JavaScript ES6 Flashcards
What is a code block? What are some examples of a code block?
A code block refers to the code within the curly braces.
Examples of code blocks include functions, loops, and conditionals.
What does block scope mean?
Block scope defines the availability of a variable to only within it’s code block
What is the scope of a variable declared withconstorlet?
Block scope
What is the difference betweenletandconst?
let can be reassigned
const cannot be reassigned
Why is it possible to.push()a new value into aconstvariable that points to anArray?
Pushing is changing the value to the array in memory space, but not reassigning the reference value.
How should you decide on which type of declaration to use?
Prefer const, unless a variable needs to be mutated.
What is the syntax for writing a template literal?
Back ticks start and end `` with any variables starting with dollar sign wrapped in curly braces.
Hello ${name}!
What is “string interpolation”?
The ability to substitute part of the string for the values of variables or expressions
What is destructuring, conceptually?
Assignment of javascript object properties to variables
What is the syntax forObjectdestructuring?
Variable declaration Curly brace with variable(s) *If renaming propertyname : new name* Assignment Operator Object to destructure
e.g.
let { firstName, lastName } = person;
What is the syntax forArraydestructuring?
Variable declaration
Square Bracket with variable(s)
Assignment Operator
Array to destructure
How can you tell the difference between destructuring and creatingObject/Arrayliterals?
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
What is the syntax for defining an arrow function?
- Variable keyword
- Variable name
- Parameters
- Arrow
- Bracket (Only required if statement)
When an arrow function’s body is left without curly braces, what changes in its functionality?
- The function can only have one line of code
- The code block must be an expression (code that resolves to value)
How is the value ofthisdetermined within an arrow function?
- The value of this is determined by it’s parent code block (outward with arrow functions)