What is SpreadElement in ECMAScript documentation? Is it the same as Spread syntax at MDN?

The term “spread operator” is kind of an “umbrella term” that refers to various syntactic constructs in ES6 which all look like …x. MDN does the same. However, this is misguiding, because … is not an operator (at least not in the sense the ECMAScript spec uses the term “operator”). It doesn’t generate a value … Read more

ES6 – Finding data in nested arrays

You have to return something from the callback of the outer find. In fact, for the inner iteration you shouldn’t use find but rather some that returns a boolean for whether an element matching the condition exists within the arrray: products.find((product) => { return product.items.some((item) => { //^^^^^^ return item.name === ‘milk’; }); }); or … Read more

In the `import` syntax of ES6, how is a module evaluated exactly?

When the D module is executed, the console will print this message: A evaluated A constructor Which means that the A module was evaluated only once, even if it was imported multiple times by other modules. The evaluation rules for ES6 modules is the same as for commonjs format: A module is a piece of … Read more

ES6 module support in Chrome 62/Chrome Canary 64, does not work locally, CORS error

Unlike regular scripts, ES6 modules are subject to same-origin policy. This means that you cannot import them from the file system or cross-origin without a CORS header (which cannot be set for local files). Basically you need to run this code from a (local) server or disable same-origin in the browser for testing (do not … Read more

How to import both default and named from an ES6 module [duplicate]

The correct syntax to import both default and named exports from ES6 module is to pass the default name (whatever one wants), and named, not-default modules separated by a comma: Example: index.js import browsers, { otherValue } from ‘./browsers’; in an exemplary file tree: . └── src ├── browsers.js └── index.js Often encountered real life … Read more

JavaScript asynchronous programming: promises vs generators

There is no opposition between these two techniques: they coexist together complementing each other nicely. Promises allows you to get the result of an asynchronous operation which is not available yet. It solves the Pyramid of Doom problem. So instead of: function ourImportantFunction(callback) { //… some code 1 task1(function(val1) { //… some code 2 task2(val1, … Read more