Modern JavaScript Development Flashcards
var
in the function scope
a variable only exists within the scope of the function in which it’s declared, or the nearest parent function
let
always block scoped
cannot be hoisted
hoisting
when the JS interpreter makes two passes at your code. in first pass, the variable and function declarations are “hoisted” to the top of the code. and in the second pass they are evaluated and assignments are made.
t/f const variables are immutable
false; you can change the value they point to; you cannot change WHERE they point; i.e., you can’t reassign them
constructor
The constructor is executed automatically when creating a new instance of the class. It guarantees that an initialization function is always called. This helps maintain a valid state for the class. But you don’t have to create a constructor. If one is not included, then the JavaScript engine creates an empty one for you.
static methods
Static methods are not part of any instance of the class, meaning that you can refer to these methods without referring to an instance. The concept of static class members is not new to ES6, but the static keyword is. Prior to ES6, you had to put any methods you wanted static in the constructor. Now you can put them wherever you want in the class and just use the static keyword.
prototype methods
These methods do not include the static keyword and must be referenced with an instance.
getters and setters
These accessor functions work just like object literals and work the same as they did in ES5. Essentially you just put the get and set keywords in front of the property name. If you define a getter without a setter, then the property becomes read-only.
BDD
Behavior-driven development (BDD) is a process that was born out of Test-driven development (TDD). BDD involves organizing tests such that their behavior is tested, rather than their implementation. When designing these types of tests, think, “How can I describe, in sentence form, what this code does and what I should expect from it.”