Senior JS Flashcards
What is a code block? What are some examples of a code block?
In JavaScript, blocks are denoted by curly braces {} , for example the if else, for, do while, while, try catch and so on:
What does block scope mean?
variable definition is only valid within the block of code that it was declared in
What is the scope of a variable declared with const or let?
block scoped
What is the difference between let and const?
Let can be reassigned and const can’t
Why is it possible to .push() a new value into a const variable that points to an Array?
It is adding to the array instead of reassigning the variable
How should you decide on which type of declaration to use?
If the variable does not need to to reassigned, use const
What is the syntax for writing a template literal?
Put it inside backticks, ${} for expressions and variables
What is “string interpolation”?
String formatting: the ability to substitute part of the string for the values of variables or expressions
What is destructuring, conceptually?
Taking out part of an object and assigning it to new variables
What is the syntax for Object destructuring?
const { title, author, libraryID } = book1
What is the syntax for Array destructuring?
const [book3, book4, book5] = getBooks()
How can you tell the difference between destructuring and creating Object/Array literals?
the side of the assignment operator that the object/array is on
What is the syntax for defining an arrow function?
(parameters) => code block
() not needed with one parameter
() are needed with no parameter
{} needed for more than one line of code
When an arrow function’s body is left without curly braces, what changes in its functionality?
You don’t get a return statement
How is the value of this determined within an arrow function?
This is defined at definition time for arrow functions.
For other functions, this is determined at call time