Skip to content
Advertisement

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 there anything else that we should know if we were

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 do it, looking at the specs

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 array. Then you will be able

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 character’s Unicode code point value,

.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 clueless as to how to extract how fitzgen/wu.js

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 console prints: Why is that? Plus,

Does ES6 introduce a well-defined order of enumeration for object properties?

Does ES6 introduce a well-defined order of enumeration for object properties? Answer Note: As of ES2020, even older operations like for-in and Object.keys are required to follow property order. That doesn’t change the fact that using property order for fundamental program logic probably isn’t a good idea, since the order for non-integer-index properties depends on when the properties were created.

Advertisement