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

Exploring ES6

Max Stoiber
January 27, 2016

Exploring ES6

What is ES6, what does it add to JavaScript, and how can you use it today? This talk will answer those questions, and, in answering them, make you a more productive JavaScript developer. Learn about arrow functions, block scoping, template literals and much more!

Max Stoiber

January 27, 2016
Tweet

More Decks by Max Stoiber

Other Decks in Technology

Transcript

  1. Max Stoiber Max Stoiber – @mxstbr – mxstbr.com Freelance Front-End

    Developer @mxstbr Co-Organiser of the React Vienna Meetup
  2. Max Stoiber – @mxstbr – mxstbr.com STAGE 0: STRAWMAN STAGE

    1: PROPOSAL STAGE 2: DRAFT STAGE 3: CANDIDATE STAGE 4: FINISHED
  3. Max Stoiber – @mxstbr – mxstbr.com STAGE 0: STRAWMAN STAGE

    1: PROPOSAL STAGE 2: DRAFT STAGE 3: CANDIDATE STAGE 4: FINISHED
  4. Max Stoiber – @mxstbr – mxstbr.com STAGE 0: STRAWMAN STAGE

    1: PROPOSAL STAGE 2: DRAFT STAGE 3: CANDIDATE STAGE 4: FINISHED
  5. Max Stoiber – @mxstbr – mxstbr.com STAGE 0: STRAWMAN STAGE

    1: PROPOSAL STAGE 2: DRAFT STAGE 3: CANDIDATE STAGE 4: FINISHED
  6. Max Stoiber – @mxstbr – mxstbr.com STAGE 0: STRAWMAN STAGE

    1: PROPOSAL STAGE 2: DRAFT STAGE 3: CANDIDATE STAGE 4: FINISHED
  7. Max Stoiber – @mxstbr – mxstbr.com STAGE 0: STRAWMAN STAGE

    1: PROPOSAL STAGE 2: DRAFT STAGE 3: CANDIDATE STAGE 4: FINISHED
  8. Max Stoiber – @mxstbr – mxstbr.com if (true) { let

    a = 0; } console.log(a); // "ReferenceError"
  9. Max Stoiber – @mxstbr – mxstbr.com (function() { var a

    = 0; }()); console.log(a); // "ReferenceError"
  10. Max Stoiber – @mxstbr – mxstbr.com { let a =

    0; } console.log(a); // "ReferenceError"
  11. Max Stoiber – @mxstbr – mxstbr.com var name = "Max";

    var twitter = "@mxstbr"; console.log("Find " + name + " on Twitter: " + twitter); // "Find Max on Twitter: @mxstbr"
  12. Max Stoiber – @mxstbr – mxstbr.com const name = "Max";

    const twitter = "@mxstbr"; console.log(`Find ${name} on Twitter: ${twitter}`); // "Find Max on Twitter: @mxstbr"
  13. Max Stoiber – @mxstbr – mxstbr.com var obj = {

    hello: function(name) { console.log("Hello", name); } } obj.hello("world"); // "Hello world"
  14. Max Stoiber – @mxstbr – mxstbr.com const obj = {

    hello: (name) => { console.log(`Hello ${name}`); } } obj.hello("world"); // "Hello world"
  15. Max Stoiber – @mxstbr – mxstbr.com function Person(age) { //

    this = instance of Person this.age = age; setInterval(function growUp() { this.age++; // Does not refer to the Person instance! }, 1000); } var Max = new Person(19);
  16. Max Stoiber – @mxstbr – mxstbr.com function Person(age) { //

    self = instance of Person var self = this; self.age = age; setInterval(function growUp() { self.age++; // Correctly refers to the Person instance! }, 1000); } var Max = new Person(19);
  17. Max Stoiber – @mxstbr – mxstbr.com function Person(age) { this.age

    = age; setInterval(function growUp() { this.age++; // Correctly refers to the Person instance! }.bind(this), 1000); // Bind the Person instance! } var Max = new Person(19);
  18. Max Stoiber – @mxstbr – mxstbr.com function Person(age) { this.age

    = age; setInterval(() => { // Does not bind its own “this”! this.age++; // Correctly refers to the Person instance! }, 1000); } const Max = new Person(19);
  19. Max Stoiber – @mxstbr – mxstbr.com function add(x, y) {

    x = x || 0; y = y || 0; return x + y; }
  20. Max Stoiber – @mxstbr – mxstbr.com function foo() { console.log("bar");

    } var funcs = { foo: foo }; funcs.foo(); // "bar"
  21. Max Stoiber – @mxstbr – mxstbr.com var employees = ["Max",

    "Peter", "Hans"]; var Max = employees[0]; var Peter = employees[1]; var Hans = employees[2]; console.log(Max, Peter, Hans); // "Max" "Peter" "Hans"
  22. Max Stoiber – @mxstbr – mxstbr.com const employees = ["Max",

    "Peter", “Hans"]; let [ Max, Peter, Hans ] = employees; console.log(Max, Peter, Hans); // "Max" "Peter" "Hans"
  23. Max Stoiber – @mxstbr – mxstbr.com var Max = {

    name: "Max Stoiber", occupation: "Developer" } var name = Max.name; var occupation = Max.occupation; console.log(name, occupation); // "Max Stoiber" "Developer"
  24. Max Stoiber – @mxstbr – mxstbr.com let Max = {

    name: "Max Stoiber", occupation: "Developer" } let { name, occupation } = Max; console.log(name, occupation); // "Max Stoiber" "Developer"
  25. Max Stoiber – @mxstbr – mxstbr.com function Person(age) { this.age

    = age; } Person.prototype.growUp = function () { return this.age += 1; }; var Max = new Person(19); Max.growUp(); console.log(Max.age); // "20"
  26. Max Stoiber – @mxstbr – mxstbr.com class Person { constructor(age)

    { this.age = age; } growUp() { this.age += 1; } } const Max = new Person(19); Max.growUp(); console.log(Max.age); // "20"
  27. Max Stoiber – @mxstbr – mxstbr.com let & const Blocks

    Template Literals Arrow Functions Default Argument Values Object Literals Destructuring Classes