-
Unlike variables declared with var that are function-scoped, variables declared with let are block-scoped: they only exist in the block they are defined in.
-
In the Chrome Development Tool > Network > Disable Cache
-
Modules have been available in JavaScript through third-party libraries. ECMAScript 6 adds native support for modules to JavaScript. When you compile a modular ECMAScript 6 application to ECMASCript 5, the compiler relies on a third party library to implement modules in ECMAScript 5. Webpack and Browserify are two popular options, and Babel supports both (and others).
-
The ECMAScript 6 arrow function syntax is a shorthand for the ECMAScript 5 function syntax. It supports both block and expression bodies. The value of this inside the function is not altered: it is the same as the value of this outside the function. No more var self = this to keep track of the current scope.
-
Current browsers don’t support all the new ECMAScript 6 (aka ECMAScript 2015) features yet (see comptability table). You need to use a compiler (transpiler) to transform your ECMAScript 6 code to ECMAScript 5 compatible code. Although there are other options, Babel has become the de-facto standard to compile ECMAScript 6 applications to a version of ECMAScript that can run in current browsers. Babel can also compile other versions of ECMAScript as well as React’s JSX.
-
Promises have replaced callback functions as the preferred programming style for handling asynchronous calls. A promise is a holder for a result (or an error) that will become available in the future (when the async call returns). Promises have been available in JavaScript through third-party libraries (for example, jQuery and q). ECMAScript 6 adds built-in support for promises to JavaScript.
-
What you know as JavaScript in browsers and in Node.js is actually a superset of ECMAScript
-
Bindings declared using const are considered constants, meaning their values cannot be changed once set.
-
Constants, like let declarations, are block-level declarations. That means constants are no longer accessible once execution flows out of the block in which they were declared, and declarations are not hoisted.
-
The value a constant holds can be modified if it is an object.
const
prevents modification of the binding, not modification of the bound value. -
Use const by default, and only use let when you know a variable’s value needs to change.
-
ECMAScript 6 supports Unicode normalization forms by giving strings a
normalize()
method. -
ECMAScript 6 adds
includes()
,startsWith()
,endsWith()
andrepeat()
method to strings. -
A template tag performs a transformation on the template literal and returns the final string value. This tag is specified at the start of the template.
-
Rest parameters have two restrictions. The first restriction is that there can be only one rest parameter, and the rest parameter must be last. The second restriction is that rest parameters cannot be used in an object literal setter.
-
All functions in an ECMAScript 6 program will have an appropriate value for their name property.
-
JavaScript has two different internal-only methods for functions: [[Call]] and [[Construct]]. When a function is called without new, the [[Call]] method is executed, which executes the body of the function as it appears in the code. When a function is called with new, that’s when the [[Construct]] method is called.
-
ECMAScript 6 introduces the new.target metaproperty. A metaproperty is a property of a nonobject that provides additional information related to its target (such as new).
-
Block-level functions are hoisted to the top of the block in which they are defined.
-
But arrow functions behave differently than traditional JavaScript functions in a number of important ways: 1. No this, super, arguments, and new.target bindings 2. Cannot be called with new 3. No prototype 4. Can’t change this 5. No arguments object 6. No duplicate named parameters.
-
Even though there is no explicit return statement, this arrow function will return the first argument that is passed in.
-
Think about tail call optimization whenever you’re writing a recursive function, because it can provide a significant performance improvement, especially when applied in a computationally expensive function.
-
When an object property name is the same as the local variable name, you can simply include the name without a colon and value.
-
ECMAScript 6 introduces the
Object.is()
method to remedy the remaining inaccuracies of the identically equals operator. -
It’s now possible to modify an object’s prototype after it’s been created thanks to ECMAScript 6’s Object.setPrototypeOf() method.
-
When you’re using destructuring to declare variables using var, let, or const, you must supply an initializer (the value after the equal sign).
-
In ECMAScript 6, you can use rest items to clone an array.
-
ECMAScript 6 introduces symbols as a primitive type. (The language already had five primitive types: strings, numbers, Booleans, null, and undefined.
-
ECMAScript 6 introduces symbols as a primitive type. (The language already had five primitive types: strings, numbers, Booleans, null, and undefined.
-
ECMAScript 6 added sets and maps to JavaScript.
-
Keep in mind that although sets are great for tracking values and forEach() lets you work on each item sequentially, you can’t directly access an item by index like you can with an array. If you need to do so, the best option is to convert the set to an array.
-
Converting an array to a set is easy because you can pass the array to the Set constructor; converting a set back to an array is also easy if you use the spread operator (...).
-
ECMAScript 6 also includes weak sets, which only store weak object references and cannot store primitive values. A weak reference to an object doesn’t prevent garbage collection if it’s the only remaining reference.
-
Keep in mind that an error will be thrown if the array contains any nonobject values, because WeakSet can’t accept primitive values.
-
You can initialize a map with data by passing an array to the Map constructor. Each item in the array must itself be an array where the first item is the key and the second is that key’s corresponding value. Therefore, the entire map is an array of these two-item arrays.
-
It’s best to use weak sets only for tracking objects that need to be grouped together.
-
Generator functions are indicated by an asterisk character (*) after the function keyword and use the new yield keyword.
-
The for-of statement will throw an error when you use it on a non-iterable object, null, or undefined.
-
The spread operator and
for-of
ignore any value specified by a return statement. As soon as they see done is true, they stop without reading the value. However, iterator return values are helpful when delegating generators. -
Class declarations and class expressions are not hoisted.
-
Classes that inherit from other classes are referred to as derived classes. Derived classes require you to use
super()
if you specify a constructor; if you don’t, an error will occur. You must callsuper()
before accessing this in the constructor. Becausesuper()
is responsible for initializing this, attempting to access this before callingsuper()
results in an error. The only way to avoid callingsuper()
is to return an object from the class constructor. -
An internal [[PromiseState]] property is set to "pending", "fulfilled", or "rejected" to reflect the promise’s state. This property isn’t exposed on promise objects, so you can’t determine which state the promise is in programmatically. But you can take a specific action when a promise changes state by using the then() method.
-
Prototype proxy traps have some restrictions. First, the getPrototypeOf trap must return an object or null, and any other return value results in a runtime error. The return value check ensures that Object.getPrototypeOf() will always return an expected value. Second, the return value of the setPrototypeOf trap must be false if the operation doesn’t succeed. When setPrototypeOf returns false, Object.setPrototypeOf() throws an error. If setPrototypeOf returns any value other than false, Object.setPrototypeOf() assumes the operation succeeded.
-
You can use the ownKeys trap to, for example, filter out certain property keys that you don’t want used when the Object.keys() method, the Object.getOwnPropertyNames() method, the Object.getOwnPropertySymbols() method, or the Object.assign() method is used.
-
Using a combination of proxy traps and reflection API methods, it’s possible to filter some operations to behave differently only in certain conditions while defaulting to the built-in behavior.
-
A module is JavaScript code that automatically runs in strict mode with no way to opt out. Keep in mind that no matter how many times you use a module in import statements, the module will execute only once. Keep in mind that the default must come before the non-defaults in the import statement. Imports without bindings are most likely to be used to create polyfills and shims.
Reference:
- ECMAScript 6 Tutorial
- Understanding ECMAScript 6