Questions tagged [ecmascript-6]

The 2015 version of the ECMAScript specification, now a standard (ECMAScript 2015). Only use this tag where the question specifically relates to new features or technical changes provided in ECMAScript 2015.

ECMAScript 2015 (also known as ECMAScript 6) is the 2015 specification for the language (now superseded by the yearly released versions, managed by TC39). ES2015 adds significant updates to the language and its implementation in major JavaScript engines is almost complete (except legacy browsers, like Internet Explorer).

The tag or its alias should be used when your question covers one of the ES2015/ES6 features.

Related, transpiler specific tags are: ,


Features

  • Arrow functions
  • Classes
  • Enhanced Object Literals
  • Template Strings
  • Destructuring
  • Default + Rest + Spread
  • let + const
  • Iterators + for..of
  • Generators
  • Unicode
  • Modules
  • Module Loaders
  • Map + Set + Weakmap + Weakset
  • Proxies
  • Symbols
  • Subclassable Built-ins
  • Promises
  • Math + Number + String + Array + Object APIs
  • Binary and Octal Literals
  • Reflect API
  • Tail Calls
  • Typed arrays and DataViews

Useful Links

29895 questions
14
votes
2 answers

EcmaScript-6 backward compatibility

I am curious to understand/figure-out if the ECMAScript-6 new-changes will work on the old browsers or not. Why I am asking this question is: I remember the introduction of 'use strict'; in ECMAScript-5, it was meant for the compatibility with the…
dopeddude
  • 4,943
  • 3
  • 33
  • 41
14
votes
2 answers

How can I require a directory in ES6?

I know I can require a file in ES6 like this: require('./config/auth'); When I try to do this require('./config/'); I get: Module not found: Error: Cannot resolve directory './config'. Why does this happen? How can I require a directory?
Jason Swett
  • 43,526
  • 67
  • 220
  • 351
14
votes
2 answers

Angular.js DI with (ES6) classes and inheritance

Background, current implementation of classes/modules in our app is common.js and CoffeeScript classes. I'm desperately looking for a solution to work with ES6 or TypeScript, but the problem remains. How to do DI with class inheritance using…
Lee Hambley
  • 6,270
  • 5
  • 49
  • 81
14
votes
5 answers

Can I pass a parameter to ES6 generator function

Here's a ES6 generator: function *Gen() { var input1 = yield 'output1' } var gen = Gen() gen.next('input1').value // return 'output1' gen called 1st time, return output1 but the variable input1 doesn't equal 'input1' which passed in , the…
mko
  • 21,334
  • 49
  • 130
  • 191
14
votes
3 answers

Maven Plugin which transpiles ES6 to ES5 which uses Traceur or Babel

Is there already a preferred way how to transpile ECMAScript6 code to ECMAScript5 using traceur or Babel (formely named 6to5) in a maven project? I have already searched the net without any success.
Daniel K.
  • 5,747
  • 3
  • 19
  • 22
14
votes
1 answer

Explain question mark (?) used in ES6/JSX code

I'm using a library called react-forms in my React app. To better understand how it works I've been reading the code, but a convention keeps popping up which confuses me. Here's the ES6/JSX code: 'use strict'; var React =…
Miles
  • 273
  • 3
  • 9
13
votes
3 answers

What was the motivation for introducing a separate microtask queue which the event loop prioritises over the task queue?

My understanding of how asynchronous tasks are scheduled in JS Please do correct me if I'm wrong about anything: The JS runtime engine agents are driven by an event loop, which collects any user and other events, enqueuing tasks to handle each…
bluprince13
  • 4,607
  • 12
  • 44
  • 91
13
votes
1 answer

What is fesm2015 and how it relates to esm2015?

I know that esm2015 refers to ecmascript modules described by the ecmascript 2015 specification (modules section) In some libraries under node_modules/ I see, next to the directory esm2015/, another one called fesm2015/. What is fesm2015? Does it…
Marinos An
  • 9,481
  • 6
  • 63
  • 96
13
votes
3 answers

Why are useState variables `const` in react?

My understanding is, when using useState(), we should declare the array as such: const [someBooleanValue, setSomeBooleanValue] = useState(false) Instead of let [someBooleanValue, setSomeBooleanValue] = useState(false) Normally, const is used on…
yalpsid eman
  • 3,064
  • 6
  • 45
  • 71
13
votes
2 answers

How to change nested property of an object using spread operator?

This is a clean version of the my situation: const person1 = { name: "Person1 Name", hairColor: "Brown", backpack: { color: "Army-Green", content: [ "item1", "item2", "..." ] …
13
votes
1 answer

AWS Lambda using Node Js gives "connect ETIMEDOUT" on http.request()

I have written lambda function that retrieve s3 Url whenever any new object created on s3 bucket. after retrieve s3Url this lambda make request to my server over REST Call. I observed cloud watcher. It failed to send request to my Server I don't…
13
votes
3 answers

How to get deep-equality of keys in ES6 Map? Alternative to using complex object as ES6 Map key?

Here is some example Javascript (ES6) code that does not do what one might intuitively imagine. const exampleMap = new Map([[{a: 1}, 2]]); console.log(exampleMap.get({a: 1})); As it turns out, this prints undefined. Why? The reasoning is covered in…
Ming
  • 1,613
  • 12
  • 27
13
votes
2 answers

Jest : TypeError: require(...) is not a function

The application is written by React with ES6 so import and export statements are used inside the application. So Jest is configured to work compatible with ES6, but compiled node_modules dependencies are causing an error which is TypeError:…
oyilmaztekin
  • 713
  • 1
  • 7
  • 25
13
votes
2 answers

How does same value zero algorithm works?

I was going through map chapter in Javascript.info and there is a link given to SameValueZero algorithm. Can someone explain how does that algorithm works in simple words. I tried going through the link but can't find anything.
Johnny Depp
  • 161
  • 1
  • 6
13
votes
4 answers

How to destructure nested object with null value using default value

When trying to destructure a nested object which could be null, the default value is not being used. I have accomplished this by destructuring in multiple stages, but would rather do it in a single stage if possible. const obj = { a: null }; const {…
ut9081
  • 787
  • 6
  • 11