Skip to content

Tag: ecmascript-6

Using Node.js require vs. ES6 import/export

In a project I am collaborating on, we have two choices on which module system we can use: Importing modules using require, and exporting using module.exports and exports.foo. Importing modules using ES6 import, and exporting using ES6 export Are there any performance benefits to using one over the other? Is …

How to unset a Javascript Constant in ES6?

I read this post, using delete keyword, we can delete JavaScript variable. But when I tried the same operations with constant but it is returning false when I try to delete constant. Is there any way to delete constants from memory? I tried this answer but its also not working. Answer You can’t directly…

JSON stringify a Set

How would one JSON.stringify() a Set? Things that did not work in Chromium 43: I would expect to get something similar to that of a serialized array. Answer JSON.stringify doesn’t directly work with sets because the data stored in the set is not stored as properties. But you can convert the set to an ar…

Is it possible to sort a ES6 map object?

Is it possible to sort the entries of a es6 map object? results in: Is it possible to sort the entries based on their keys? Answer According MDN documentation: A Map object iterates its elements in insertion order. You could do it this way: Using .sort(), remember that the array is sorted according to each ch…

.map() a Javascript ES6 Map?

How would you do this? Instinctively, I want to do: I’ve haven’t gleaned much from the documentation on the new iteration protocol. I am aware of wu.js, but I’m running a Babel project and don’t want to include Traceur, which it seems like it currently depends on. I also am a bit cluel…

ECMAScript 6: what is WeakSet for?

The WeakSet is supposed to store elements by weak reference. That is, if an object is not referenced by anything else, it should be cleaned from the WeakSet. I have written the following test: Even though my [1, 2, 3] array is not referenced by anything, it’s not being removed from the WeakSet. The cons…