Questions tagged [es6]

ECMAScript 2015, standardized as ECMA-262 6th Edition

ECMAScript (ES) is a scripting-language specification created to standardize JavaScript, so as to foster multiple independent implementations. The ECMA-262 6th Edition was published in June 2015.

30 questions
302
votes
5 answers

Is there any reason to use the "var" keyword in ES6?

Babel's guide to ES6 says: let is the new var. Apparently the only difference is that var gets scoped to the current function, while let gets scoped to the current block. There are some good examples in this answer. I can't see any reason to use…
callum
  • 10,377
  • 9
  • 30
  • 33
227
votes
6 answers

How much should I be using 'let' vs 'const' in ES6?

I've been writing a lot of ES6 code for io.js recently. There isn't much code in the wild to learn from, so I feel like I'm defining my own conventions as I go. My question is about when to use const vs let. I've been applying this rule: If…
callum
  • 10,377
  • 9
  • 30
  • 33
63
votes
2 answers

Why use `const foo = () => {}` instead of `function foo() {}`

Edit added 2+ years later I "checked" the @dandavis answer because it answers my original question, giving reasons to prefer const foo. However, I am completely convinced by the @Wayne Bloss answer that function foo() is generally…
user949300
  • 8,679
  • 2
  • 26
  • 35
50
votes
3 answers

Any point in using ES6 Map when keys are all strings?

Plain object keys must be strings, whereas a Map can have keys of any type. But I have little use for this in practice. In nearly all cases, I find myself using strings as keys anyway. And presumably new Map() is slower than {}. So is there any…
callum
  • 10,377
  • 9
  • 30
  • 33
19
votes
1 answer

different between ES6 and Javascript

What is ES6? Is it JavaScript? Or multiple language supporter? I searched for it but can't understand it, especially the page on Wikipedia. Is it better than Javascript? And what can I do in my web developing using this language? So what ES6 is,…
androidnation
  • 335
  • 1
  • 2
  • 5
16
votes
2 answers

Why doesn't ES6 have thin-arrow functions?

ES6 added fat-arrow functions (=>), which have two major differences from normal functions: shorter syntax (including implicit return if you use a single-expression body) inherit this from surrounding scope These are both very useful features, but…
callum
  • 10,377
  • 9
  • 30
  • 33
14
votes
3 answers

Why can't an ES2015 WeakMap have primitive keys?

There are six primitive data types in JavaScript: Boolean, Number, String, Symbol, undefined, null A WeakMap can't have primitive data types as keys. And a WeakSet can't have primitive values. Why is this? Is it a language design decision (in which…
callum
  • 10,377
  • 9
  • 30
  • 33
12
votes
3 answers

How does JS Promises works being single threaded

Javascript is single threaded. What I understand from this is if JS i executing on line of code lets say a function. It cannot go to the next line unless that function has been removed from the stack. With that being said, I do not understand, how…
user212699
6
votes
1 answer

Why would I use es6 Set prototype -> 'entries'

According to mdn's "Set" documentation, entries is provided as a convenience method ...to keep the API similar to the Map object, each entry has the same value for its key and value here, so that an array [value, value] is returned. My question is…
aaaaaa
  • 169
  • 4
6
votes
2 answers

Idiomatic way to write JavaScript class that maintains state and tells you when that state has changed

I am an experienced C++ developer but new to JavaScript. I want to write an ES6 JavaScript class that maintains state. How do I tell when state has changed? I can think of two ways to do this. One way is to inspect an instance of the class to see…
Armbie
  • 61
  • 2
6
votes
2 answers

Nested classes via a getter (to emulate namespacing)

So, we all know that ES6's introduced syntax is definitely sugar over what we've been doing, previously. That being said, we still don't have namespaces (which would be nice...) The problem that I'm trying to solve is converting old code into es6.…
ndugger
  • 568
  • 1
  • 6
  • 8
5
votes
1 answer

Any reason to continue using plain strings in ES2015?

My current coding style is to use single-quoted strings as a default, and use backticked template literals whenever I need to concatenate a value into a string. But I'm now wondering what's the point in having two kinds of string at all? Maybe it…
callum
  • 10,377
  • 9
  • 30
  • 33
4
votes
1 answer

How can 'yield' be added as a keyword in ES6 if it wasn't a reserved word?

yield is not a reserved word in JavaScript, yet ES6 makes it a keyword. I thought the point of reserved words was for backwards compatibility. For example, let and const were reserved, so you couldn't use those words as variable names in your ES5…
callum
  • 10,377
  • 9
  • 30
  • 33
3
votes
1 answer

Why tabs are evil in ES6?

As I have recently started using ES6 in production, I was going through an ES6 style guide (having more than 350 stars on GitHub). This guide mentions at least three times that "Tabs are evil. Don't use them!" Also, another very popular JavaScript…
mg007
  • 155
  • 1
  • 4
3
votes
1 answer

Do we need redux here?

In an ongoing project my team is building a new web application that relies heavily on a rest api. As we decided to try react we naturally came to implement redux and a middleware, as we've read this is the way to go. However, further into the…
1
2