Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modern JavaScript beyond ES6

Modern JavaScript beyond ES6

The main focus of this talk is showcasing JavaScript features added after the ECMAScript2015 (ES6) release. We’ll cover some of the useful innovations and syntactic improvements in ECMAScript <2016,2017,2018,2019> releases and demonstrate how they enable us to achieve more with less code.

Avatar for Nemanja Stojanovic

Nemanja Stojanovic

March 17, 2019
Tweet

More Decks by Nemanja Stojanovic

Other Decks in Programming

Transcript

  1. Why do we care? • JavaScript is the lingua franca

    of the Web • (almost) every website ever made has some JavaScript running on it https://w3techs.com/technologies/details/cp-javascript/all/all
  2. Why do we care? https://octoverse.github.com/projects • most contributors in public

    and private repositories, organizations of all sizes, and every region of the world. 4 years in a row
  3. Why do we care? NPM (registry of JS packages) is

    the largest package registry in the world
  4. Why do we care? NPM (registry of JS packages) is

    the largest package registry in the world
  5. Why do we care? According to Stack Overflow’s Annual Survey

    of 2018, for the sixth year in a row, JavaScript is the most commonly used programming language.
  6. Why do we care? (Jeff) Attwood’s Law (co-founder of StackOverflow):

    any application that can be written in JavaScript, will eventually be written in JavaScript.
  7. What can we code in JS? • Websites • Mobile

    apps • Backend servers • IOT controllers • Desktop apps
  8. What is ECMAScript? Quick History • JavaScript name is an

    attempt to capitalize on the success of Java. • Netscape submits JavaScript to the ECMA International Standards organization. • This results in a new language standard named ECMAScript. • JavaScript is the most popular implementation of that standard
  9. What is ES6? Quick History • ESX stands for ECMAScriptX

    • In 2009 the ES5 version of the standard is released • In 2015 the ES6 version of the standard is released • At the same time, a naming convention of ES<year-of-release> was established • “ES6” === “ES2015”
  10. Functions - first class citizens • Behave like values (we

    can store them in variables, pass them as parameters etc.)
  11. • All instances of that function have access to it

    *.prototype.<method> • Special object available to each function
  12. Static methods • Attached to the function and not on

    the prototype • Available via the function itself, not via instances of it
  13. • Takes an optional 2nd argument which is the index

    from which to start the search Array.prototype.includes
  14. String.prototype.padStart • Pad a string with another string (from the

    left) until the resulting string reaches the given length
  15. Trailing commas in parameters • Adding a new parameter allows

    us to add a new line without modifying the previous • Useful for version-control systems like Git (gives simpler code-change diffs)
  16. Rest vs Spread in ES6 ... • Rest gathers what’s

    remaining • Spread expands what exists
  17. Async iteration • for await of • Wait for each

    Promise to resolve before doing to the next iteration
  18. How does iteration work? • We need to understand 3

    concepts: iterable, iterator, and iteratorResult
  19. What is an iterable? • Remember Symbol.iterator? • An object

    can mark itself as iterable by having a method whose key is Symbol.iterator
  20. What is an iterator? • Iterator has method called next

    that returns the next iteratorResult each time it’s called
  21. What is an iteratorResult? • An object wrapper around each

    item during an iteration • Contains the current item and a boolean indicating if we reach the end of the iteration
  22. Ok but what about async iteration? • Symbol.asyncIterator to the

    rescue! • Method next of an async iterator wraps the iteratorResult in a Promise
  23. RegExp Named Capture Groups • We can use /k to

    reference a named capture group within the regex itself
  24. New RegExp lookaround • “Lookaround” in a Regex specifies what

    the surroundings of a location must look like
  25. Look ahead • x(?=y) – positive (matches x when it's

    followed by y) • x(?!y) – negative (matches x when it's followed by y) Look behind • (?<=x)y – positive (matches y when it's preceded by x) • (?<!x)y – negative (matches y when it's preceded by x)
  26. RegExp unicode property escape • Match any unicode char based

    on its script • ES2015 introduced /u flag to match any unicode char • ES2018 adds /p{unicodeCharacterProperty} to match a particular unicode group
  27. Dynamic imports • Code-splitting • Improves performance (only load things

    when you need them => faster initial load) • Adjusting to factors only know at runtime