Call parent function which is being overridden by child during constructor chain in JavaScript(ES6) [duplicate]

You seem to be operating under a misconception that there are two objects A and B when you are in the constructor of the derived class B. This is not the case at all. There is one and only one object. Both A and B contribute properties and methods to that one object. The value … Read more

Why use an ES6 Map instead of a plain javascript object?

Anything can be used as a key in a map. Maps are ordered, and that allows for iteration. Combining 1 and 2, when you iterate over a map, you’ll get a useful array of key-value pairs! Check out the map.prototype.forEach() documentation. Source: Another good question/answer exchange. Worth marking this one as a duplicate. Update: Adding … Read more

Is there a downside to using ES6 template literals syntax without a templated expression?

Code-wise, there is no specific disadvantage. JS engines are smart enough to not have performance differences between a string literal and a template literal without variables. In fact, I might even argue that it is good to always use template literals: You can already use single quotes or double quotes to make strings. Choosing which … Read more

Array.fill(Array) creates copies by references not by value [duplicate]

You could use Array.from() instead: Thanks to Pranav C Balan in the comments for the suggestion on further improving this. let m = Array.from({length: 6}, e => Array(12).fill(0)); m[0][0] = 1; console.log(m[0][0]); // Expecting 1 console.log(m[0][1]); // Expecting 0 console.log(m[1][0]); // Expecting 0 Original Statement (Better optimized above): let m = Array.from({length: 6}, e => … Read more

How to check if a Map or Set is empty?

You use its size property. Both Maps and Sets have it (here and here). const populatedSet = new Set([‘foo’]); console.log(populatedSet.size); // 1 const populatedMap = new Map([[‘foo’, 1]]); console.log(populatedMap.size); // 1 (Side note: WeakMaps and WeakSets don’t have size or several other features their “strong” counterparts have, in order to keep their implementations, and code … Read more