29,927 questions
-7
votes
0
answers
64
views
How to filter an array of objects based on multiple properties in ES6? [duplicate]
I have spent time researching this on MDN and exploring similar questions on Stack Overflow. Most solutions cover static filtering (e.g., item.category === 'Web'), but my challenge is that the filters ...
Advice
1
vote
6
replies
118
views
Why does JavaScript’s Math.round(-1.5) round toward positive infinity instead of following standard rounding?
If we round a negative number to the nearest integer in JavaScript, in the case of a tie (i.e., a fractional part of 0.5), the nearest integer is the one closer to positive infinity. For example: Math....
Advice
0
votes
4
replies
73
views
Seeking Roadmap and Advanced Resources for Deepening JavaScript Knowledge
Hi everyone, I am a developer with a deep interest in JavaScript. I have been working with the language for some time, but I’ve reached a plateau where I'm unsure of my current proficiency level or ...
Best practices
1
vote
4
replies
147
views
How can one create mini quiz app project with pure vanilla JavaScript. i'm a learner, after the structuring the html / css i couldn't continue
How can i create a mini quiz app with pure vanilla JavaScript which takes questions and presents options which include the correct answer and output the scores with a next button which switches the ...
1
vote
0
answers
73
views
How to use DuckDB browser wasm module without bundler?
The documentation says:
Statically Served
It is possible to manually download the files from https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm/dist/.
import * as duckdb from '@duckdb/duckdb-wasm';
...
Best practices
0
votes
10
replies
95
views
How do I use async function as Promise executor in js?
How do I use async function as Promise executor in js?
The following won't work:
new Promise(async (resolve, reject) => {
//something
});
Advice
0
votes
0
replies
55
views
How do we load ML5 as an ES6 Module?
How do we load ML5 as an ES6 Module?
I have tried:
import ml5 from "https://unpkg.com/[email protected]/dist/ml5.min.js";
// but no default export
import * as ml5 from "https://unpkg.com/ml5@1....
-1
votes
1
answer
96
views
Why does `Array(3).map(x => 42)` return an empty array instead of `[42, 42, 42]` in JavaScript? [duplicate]
I was brushing up on Array for an implementation and I stumbled on this discovery, I expected the following code to give me an array filled with the number 42:
Array(3).map(x => 42)
But instead, ...
-4
votes
1
answer
154
views
Comparing for loops vs spread and concat for merging arrays in JavaScript — performance and best practices? [closed]
I'm learning JavaScript and practicing merging arrays. Here's one of the methods I wrote using two for loops:
const arr1 = [4, 5, 7, 9, 8];
const arr2 = [-1, -2, 0, 12];
const arr3 = [];
for (let i = ...
2
votes
1
answer
121
views
How does the JavaScript engine handle object identity and prototype inheritance between ShadowRealms and the main execution context?
I’m experimenting with the ECMAScript proposal for ShadowRealm and ran into some deeply unintuitive behavior around object identity, function bindings, and prototype inheritance across realms.
...
-4
votes
1
answer
141
views
HtmlService include() function breaks ES6 syntax in included files - template processing issue
I'm getting syntax errors when trying to modularize a Google Apps Script HTML project. The issue appears to be related to how the HTML service processes included files as templates rather than raw ...
-1
votes
2
answers
130
views
for await (let i of asyncIterable); 'i' is declared but its value is never read
I am using ixjs/AyncIterable (pull-model).
The simplest code I need to write at the end, to initiate the stream processing is:
for await (let i of asyncIterable);
But eslint does not like this:
'i' ...
2
votes
1
answer
108
views
Is it allowed in javascript to modify the handler after proxy has already been created?
I modify the handler object after proxy's creation, and obtain intended result. But nowhere in mdn document such pattern, can i rely on this pattern to work consistently across browser/in future?
...
0
votes
2
answers
222
views
Main chunk in Webpack references the wrong runtime chunk
In an existing web app written in Vue and PHP, we are trying to add a Micro Frontend using Module Federation.
After we configured the app, I found out that the watch command wasn't working correctly. ...
1
vote
2
answers
120
views
ES6 static class extends EventTarget
I wish to create a class which extends EventTarget, allowing addEventListener() and dispatchEvent() to be invoked on it.
Logically, my class wants to be a singleton; if a page accidentally ...
1
vote
0
answers
80
views
Inheriting constructor documentation in JSDoc with ES6 classes
I am writing documentation for some classes written using the ES6 class syntax. I have some classes which inherit their constructor from their parent class, as below:
/**
* @class
*/
class Parent {
...
2
votes
2
answers
171
views
Alternative to 'assert' in Node JS with strict mode
I have a Firebase Functions project that has "type" set to "module" in package.json so that I can use ES6 syntax. Some of the files import data from another json file with a line ...
-3
votes
1
answer
81
views
Why is the return not excuted? [closed]
my codes
console results
Here are my React codes. I know that if you write a function with a parenthesis, it will be called immediately (in this case, it will be called when elements render, I have ...
-1
votes
1
answer
400
views
How to import a component from published library and how to get component key
I'm working on a figma plugin where in I need to use the components
which are in published library assets. I know I should be using
figma.importComponentByKeyAsync() of figma plugin API, but I m not
...
0
votes
0
answers
153
views
How to solve Open Redirect vulnerability
In a webapp we are trying to solve an Open Redirect vulnerability.
The code is like this:
window.location.href = DOMPurify.sanitize(data.href);
Which apparently is vulnerable. One recommended solution ...
1
vote
1
answer
57
views
Why do private fields not get overridden in subclasses?
I'm trying to create a parent class A with a private field #abc and a subclass B that overrides this field. However, when I call methods from the parent class that access the private field, it still ...
0
votes
1
answer
46
views
Safari modulepreload for relative paths fails
I am including the vega module in a module:
import vega from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
This works without console errors on Chrome, Edge, and Firefox, but not Safari.Inspecting ...
0
votes
1
answer
58
views
Does CloudAnt support ES6 functions or not?
The CloudAnt server says it is using CouchDB 3.4.2, and ES6 support was added to CouchDB in version 3.0..., but I am not able to use fat arrow function syntax in the online view editor for my ...
0
votes
2
answers
84
views
Unexpected result is return by document.getElementsByTagName and javascript behaviour
HTML :
<html>
<body>
<div id="a">
</div>
</body>
</html>
Above is my simple html given and i wrote a function to add a children div ...
1
vote
0
answers
36
views
Are built-in static methods bound? [duplicate]
According to the specification, are built-in Javascript static methods, like Array.from, Object.assign, console.log, etc meant to be bound or do they need to be invoked via the constructor/object?
...
0
votes
1
answer
97
views
Why properties initializing don't propagate to child class in ECMASCRIPT?
I'm having some trouble wrapping my head around inheritance in ES6 classes. Searching here, most of the answers are 10+ years old so I don't think they apply still. Let's start with the sample code:
...
-1
votes
2
answers
61
views
How does React props work with es6 and object inheritance between classes
I don't even know if this is possible, something told me to do functional components but I am already too far deep into the code and I am scared to go back (this is an issue I must learn to tackle but ...
0
votes
2
answers
108
views
ES6 include references/dependencies in dynamic import
I have FileA that dynamically import FileB from different directory.
The dynamic import fail because FileB importing module 'lodash'.
The error show
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '...
-1
votes
1
answer
71
views
Arrow function this scope is undefined even when using .call or .apply [duplicate]
var obj = {
method : () =>{
console.log(this)
}
}
obj.method.apply(obj)
I'm trying to use .call or .apply to set the this context for an arrow function, but this remains undefined. ...
0
votes
1
answer
65
views
Not Cyclic Module Record in ECMAScript
The ECMAScript specification has a section about the modules. Link() is a method on Cyclic Module Record that runs another method called InnerModuleLinking, which passes the current module (namely ...
1
vote
1
answer
41
views
javascript library is not loaded into an angular typescript project
We are trying to build a javascript library (dwbn-event-webcomponents), that can be imported into a typescript project (angular 17) and also used standalone. It was installed via npm from git url.
In ...
-1
votes
1
answer
88
views
How to count documents created within specific month or year using createdAt field in mongoDB?
I'm building an admin dashboard and i want to count users created in given month or year. I'm using the countDocuments() method with the query param "createdAt" but the result is 0 and i'm ...
0
votes
1
answer
123
views
Module not found node_modules\@emailjs\nodejs\mjs\models\EmailJSResponseStatus'
I am trying to use EmailJs to send Emails from my NodeJs backend. I am using ES6 version of JS.
I installed EmailJs using command:
npm i @emailjs/nodejs
After that I checked my nodemodules directory. ...
1
vote
0
answers
64
views
Browser EventLoop prevents window load event from firing when advanced by an async substlecrypto call
Why is it happening and how to fix it? To reproduce comment/uncomment generateKey call and watch the event handler (you might want to put into a module (which is how I use it) or execute is as part ...
1
vote
0
answers
132
views
Who can explain this weird inference in TypeScript?
I'm sure this is the expected behaviour but it looks counter-intuitive for me. Given the following snippet, why is item inferred as { a: number } instead of { b: number }? I was expecting a kind of ...
-2
votes
3
answers
94
views
How can I write a JavaScript variable inside double quotation marks in a template literal? [closed]
I have this code:
const newDiv = document.createElement('div');
newDiv.innerHTML = `
<button class='btn btn-download'>
<span class='icon'>&#...
1
vote
1
answer
220
views
How do I transpile Angular 17 ES6 app to ES5 for Android 10 devices
Working on a web app for a specialized device that runs Android 10 (Webview uses Chromium <80). When I try to serve the app and test on the Android device, I get errors for using optional chaining ...
0
votes
1
answer
105
views
Converting CJS Module to ECMAScript when export contain an arrow function
On Server Application Structure documentation page of Socket.io, two methods are presented to use modules for better code clarity. Those modules are CommonJS.
I managed to translate the first to ESM, ...
0
votes
2
answers
103
views
Understanding Promise Chaining Internal Mechanics
I am learning promise chaining and I stumbled upon a doubt. Consider the below promise chain -
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("...
1
vote
1
answer
75
views
Why isn't setting attribute to an invalid value throwing?
As defined per WebIDL specification, setting attribute on an interface should convert the JS value to its IDL equivalent. It is explicitly stated that if the value cannot be converted it should throw ...
6
votes
0
answers
1k
views
HMR is not implemented for module chunk format yet
I've converted my webpack project to output ES6:
experiments: {
outputModule: true
},
output: {
library: {
type: 'module'
}
},
Now, when I run in dev mode (...
1
vote
1
answer
102
views
Building an ES6 library with webpack
I'm looking for something like html-webpack-plugin, but instead of HTML, it will output to a javascript file that loads everything else. I've found js-entry-webpack-plugin, but it doesn't output ...
-1
votes
1
answer
139
views
Can clearTimeout prevent the execution of a callback which has already been moved to the callback queue?
Consider a scenario where I have two tasks -
Task 1 is a callback which is set to be executed after 1 sec using setTimeout.
Task 2 is a synchronous/blocking task which takes comparatively more time ...
-1
votes
2
answers
83
views
Compare two array of objects and push or pop objects from first array based on second array
consider below 2 array of objects, say arr1 and arr2.
based on id, if any new item exist in arr2 copy item to arr1 and remove item from arr1 if that item not present in arr2.
Tried something like this,...
0
votes
1
answer
189
views
Material Table React - Apply To All and Apply To Group BY
I want to Apply, "Apply To All" and "Apply to GroupBy" for the rows I'm using with the use of Material UI.
I want to create a button "Apply to All". When the user Edit ...
0
votes
1
answer
30
views
Use graphql-schema-linter with a CJS config file
I have a command to run the linter graphql-schema-linter -c build-util/config but we have upgraded our project to use Vite instead of Laravel Mix. We are now using CJS files for some of the JS files ...
0
votes
0
answers
84
views
Javascript: Any way to create a class by constructing class name using strings/variables dynamically without eval? [duplicate]
I've tried myriads of ways to create new class instances dynamically, without using eval and hard coded key-value pairs, to no avail. Seemingly there is no way in modern Javascript to query the user ...
-2
votes
2
answers
112
views
How to filter an array of objects by key
There are similar questions to this but I cannot find something to tackle this one exactly.
I have an Array that is shaped like this:
AllReviews: [
{"0001": [
{"Review": &...
1
vote
1
answer
179
views
How do I implement sort by using algolia in Nextjs
I am facing issue while adding sort by feature in my Nextjs project using algolia
useEffect(() => {
setLoading(true);
const index = algoliaClient.initIndex(ALGOLIA_INDEX);
const filters ...
1
vote
0
answers
56
views
Why can't I set a private field in a function called from a superclass constructor? [duplicate]
When I run the following code in Node.js:
class Superclass {
constructor() {
this.setPrivateField();
}
setPrivateField() {
// No implementation
}
}
class Subclass extends Superclass {...