Senior JavaScript Flashcards
What is a code block? What are some examples of a code block?
Code blocks are denoted by curly braces, where we can have multiple statements.
- if…else, for, while statements
What does block scope mean?
Area within if, switch conditions or for and while loops.
- Functions are function scoped
What is the scope of a variable declared withconstorlet?
Block Scoped
What is the difference betweenletandconst?
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)
Why is it possible to.push()a new value into aconstvariable that points to anArray?
- Constants cannot be changed through re-assignment nor can they be redeclared
- For arrays we are just just adding to the “list”
How do we “freeze” values in an object
Object.freeze() to make it immutable.
How should you decide on which type of declaration to use?
If the value of the variable is not changing, use const.
What is the syntax for writing a template literal?
Instead of using single or double quotes, use backticks around the whole expression
What is “string interpolation”?
Substituting parts of the string for values of variables or expressions
What is destructuring, conceptually?
Makes it possible to unpack values from arrays, or properties from objects, into distinct variables
What is the syntax forObjectdestructuring?
What is the syntax forArraydestructuring?