ES6 Flashcards
What is the scope of a variable declared with const or let?
block scope
What does block scope mean?
Within the block
What is a code block? What are some examples of a code block?
define within { … }, if, for, while,…
What is the difference between let and const?
let can be reassigned
const cannot be assigned
Why is it possible to .push() a new value into a const variable that points to an Array?
const is mutable ONLY if it’s object
How should you decide on which type of declaration to use?
if you want to reassign value in the future use let, otherwise use const.
What is the syntax for writing a template literal?
backtick () then ${JavaScript Expression}
What is “string interpolation”?
to create strings by doing substitution of placeholders
What is destructuring, conceptually?
convenience way to extract property values of an object (in 1 line)
What is the syntax for Object destructuring?
var/let/const { property1:alias_name = ‘default_value’ , property2, … } = object;
What is the syntax for Array destructuring?
var/let/const [ element1st, element2nd, …. , element#nth ] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
{ } or [ ] is on the left side of = then destructuring
What is the syntax for defining an arrow function?
( ) => { }
When an arrow function’s body is left without curly braces, what changes in its functionality?
no code block = implicit return (return without return statement)
with { }, will require return keyword to actually return value.
{ } allows for multilines code block
How is the value of this determined within an arrow function?
the value is determine at the definition time, (parent code block)
What is “syntactic sugar”?
syntax within a programming language to make things easier to read or to express
What is the typeof an ES6 class?
function
Describe ES6 class syntax.
class ClassName {
constructor(…) {
//this.parameter = parameter;
}
methodName(…) {
//definition
}
}
What is “refactoring”?
the process of restructuring existing computer code without changing its external behavior, intend to improve the design, structure, and/or implementation of the software while preserving its functionality.
- improve code readability and reduced complexity.
How are ES Modules different from CommonJS modules?
commonJS:
- compact syntax
- designed for synchronous loading
- main use: server
ES modules:
- more compact syntax than common JS
- have support for asynchronous loading and configurable module loading
What kind of modules can Webpack support?
ECMAScript modules
CommonJS modules
AMD modules
Assets
WebAssembly modules
many more (with Loaders)
What is React?
a JS library for creating user interfaces.
What is a React element?
an object that virtually describes the DOM nodes that a component represents
How do you mount a React element to the DOM?
root = ReactDOM.createRoot(“querySelectedContainer”)
root.render(ReactElement)