
New ES2019 JavaScript features - ducaale
https://blog.logrocket.com/new-es2019-javascript-features-every-developer-should-be-excited-about/
======
lhorie
FYI, the ES2019 spec has been published[1] already and optional chaining and
pipeline operator are not in it.

If you want to know what's new in ES2019, look no further than the
[Introduction]([https://www.ecma-
international.org/ecma-262/10.0/index.html#...](https://www.ecma-
international.org/ecma-262/10.0/index.html#sec-intro)) section in the spec.

> This specification, the 10th edition, introduces a few new built-in
> functions: flat and flatMap on Array.prototype for flattening arrays,
> Object.fromEntries for directly turning the return value of Object.entries
> into a new Object, and trimStart and trimEnd on String.prototype as better-
> named alternatives to the widely implemented but non-standard
> String.prototype.trimLeft and trimRight built-ins. In addition, this
> specification includes a few minor updates to syntax and semantics. Updated
> syntax includes optional catch binding parameters and allowing U+2028 (LINE
> SEPARATOR) and U+2029 (PARAGRAPH SEPARATOR) in string literals to align with
> JSON. Other updates include requiring that Array.prototype.sort be a stable
> sort, requiring that JSON.stringify return well-formed UTF-8 regardless of
> input, and clarifying Function.prototype.toString by requiring that it
> either return the corresponding original source text or a standard
> placeholder.

[1] [https://www.ecma-
international.org/ecma-262/10.0/index.html](https://www.ecma-
international.org/ecma-262/10.0/index.html)

~~~
robotstate
Of course the two features I was most excited about aren't in the actual
spec...

------
randallsquared
This seems like a better guide to actual ES2019:
[https://medium.com/@selvaganesh93/javascript-whats-new-in-
ec...](https://medium.com/@selvaganesh93/javascript-whats-new-in-
ecmascript-2019-es2019-es10-35210c6e7f4b)

------
baron816
Why is the pipeline operator mentioned here? That’s definitely not ES2019.

~~~
SSchick
Yea, I was thinking the same, it's not even on
[https://github.com/tc39/proposals](https://github.com/tc39/proposals)

~~~
lhorie
Stage 1 proposals were moved to a separate page, presumably to reduce clutter
[https://github.com/tc39/proposals/blob/master/stage-1-propos...](https://github.com/tc39/proposals/blob/master/stage-1-proposals.md)

------
STRiDEX
I always use [http://node.green](http://node.green) because it also tells me
if I can use it yet/soon.

~~~
zaro
Thanks. I've wondered recently how to check what is supported in node.

------
crooked-v
The pipe operator is the key thing I'm really looking forward to as a general
quality of life improvement.

------
Bjartr
Wait, trimLeft/trimRight has different semantics from trimStart/trimEnd in RTL
languages. So it has to be more than a simple alias, right?

~~~
lioeters
I checked on MDN:

"The trimStart() method removes whitespace from the beginning of a string.
trimLeft() is an alias of this method."

[https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Refe...](https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)

I suspect that trimLeft was misnamed, since its "left" didn't take into
account RTL - it just meant start of string.

------
dlojudice
JS is going to be so different in 2019 that I'm expecting a revised version of
"The Good Parts"[1]

[1] [https://www.amazon.com/JavaScript-Good-Parts-Douglas-
Crockfo...](https://www.amazon.com/JavaScript-Good-Parts-Douglas-
Crockford/dp/0596517742)

~~~
eropple
That book is of an era and hasn't been particularly relevant in quite awhile.
The rise of classes as prototype sugar made a lot of the navel-gazing of
object creation mostly moot. The rise of rigorous linting took care of the
rest.

TypeScript helped a lot, too.

~~~
Roboprog
Some of us consider “class” a bad thing.

I would rather work in a language/style that draws its inspiration from Scheme
than Simula 67.

Too bad more places are picking up TypeScript rather than ClosureScript.

~~~
orangecat
_I would rather work in a language /style that draws its inspiration from
Scheme than Simula 67._

Then you should push for WebAssembly improvements so you can use whatever
language you want. As long as JavaScript is a de facto requirement for web
development it needs to be as approachable as possible to a wide developer
audience, and that means looking more like Java than Lisp.

~~~
BigJono
Or we could've considered it an opportunity to move people away from classical
inheritance and towards something that's conceptually much simpler? (which
both prototypal inheritance and functional programming are)

~~~
boomlinde
JS is and always was prototype based. The class keyword is as far as I know
just syntax sugar that creates a prototype chain and a new-able function that
assigns the prototype to self.

~~~
jwalton
The '#privateVar' syntax means that classes are no longer simply syntax sugar,
unfortunately.

~~~
eropple
Private variables could always be simulated with IIFEs. I'm pretty sure that's
actually how TypeScript does it if you compile down low enough.

------
atonse
As a former C# dev, I’m excited about the optionals.

As a current elixir dev, VERY excited about the pipe operator.

~~~
nojvek
Chaining operator is likely to land. V8 has optional support for it and Babel
has some plugins.

Pipeline operator has lots of quirks and syntax bikeshedding. I don’t think it
may land.

Especially when you can make your own pipe(x,y,z) function quite easily. Just
a guess though.

------
rkwz
I wish there was more focus on increasing the surface area of the standard
library instead of more language features like Golang

------
11235813213455
> pipeline operator

no thanks, I don't think it's an interesting feature, there are alternatives
(chaining, promises, ..) to avoid the cost of this new syntax

Other proposals I'm more excited about:

\- [https://github.com/tc39/proposal-iterator-
helpers](https://github.com/tc39/proposal-iterator-helpers)

\- [https://github.com/tc39/proposal-slice-
notation/](https://github.com/tc39/proposal-slice-notation/) (and
[https://github.com/tc39/proposal-slice-
notation/pull/32](https://github.com/tc39/proposal-slice-notation/pull/32))

------
RobertKerans
This is a very minor frustration, and I'm screaming into the abyss, but when
searching for JavaScript topics, blogposts from LogRocket pretty often come up
top of the search rankings, above more authoritative sources. Often under
_slightly_ misleading titles (such as this one) that seem chosen to capitalise
on common search terms, or else the articles are packed with keywords.
Sometimes mildly useful but mostly they're shallow and not particularly
contentful, and LogRocket seem to absolutely churn them out. Seems to have
gone down _slightly_ since moving from Medium to Hosted WP, but not much.
Nothing doing, it's just SEO and getting the name "LogRocket" in front of more
eyeballs, but just...urrgh

------
a13n
Super duper excited about optional chaining!

One thing I miss from Objective-C that I wish JS would add is the `?:`
operator – basically a shortened version of the ternary operator.

~~~
kamyarg
Do you mean

    
    
        true ? console.log("foo") : console.log("bar")
    

?

This is already there: [https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Refe...](https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)

~~~
james-mcelwain

      x ?: y 
    

is shorthand for

    
    
      x != null ? x : y

~~~
jchook
In JavaScript you can simply use the logical or operator

x || y

~~~
rimunroe
This is not equivalent. It will result in y if x is any falsy value (like
false, empty string, or 0), not just if x is nullish.

~~~
jchook
In which languages does ?: not work that way?

For example in PHP, it works exactly like you describe.

~~~
nojvek
I think that’s exactly what the nullish ?? Operator is.

You can write x ?? y

Which is x !== null and x != undefined ? x : y

------
hpen
woooh optional chaining!

------
Roboprog
Thanks for links to accurate information, those who posted

TL;DR - most of what is added in 2019 I can already do with Ramda.js, and it
works in IE11, as well.

Pity about the Ruby / Groovy style dot-condition-chaining NOT being in the
2019 features, though.

