This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function multiply(a, b) { | |
| if (b === undefined) { | |
| return function(b) { | |
| return a * b; | |
| } | |
| } | |
| return a * b; | |
| } | |
| let double = multiply(2); | |
| double(3); // => 6 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | let multiply = (a, b) => b === undefined ? b => a * b : a * b; | |
| let double = multiply(2); | |
| double(3); // => 6 | |
| multiply(2, 3); // => 6 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var Message = function(text) { | |
| this.text = text; | |
| }; | |
| var helloMessage = new Message('Hello World!'); | |
| console.log(helloMessage.text); // => 'Hello World!' | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var Message = (text) => { | |
| this.text = text; | |
| }; | |
| // Throws "TypeError: Message is not a constructor" | |
| var helloMessage = new Message('Hello World!'); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var button = document.getElementById('myButton'); | |
| button.addEventListener('click', function() { | |
| console.log(this === button); // => true | |
| this.innerHTML = 'Clicked button'; | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var button = document.getElementById('myButton'); | |
| button.addEventListener('click', () => { | |
| console.log(this === window); // => true | |
| this.innerHTML = 'Clicked button'; | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function MyCat(name) { | |
| this.catName = name; | |
| } | |
| MyCat.prototype.sayCatName = function() { | |
| console.log(this === cat); // => true | |
| return this.catName; | |
| }; | |
| var cat = new MyCat('Mew'); | |
| cat.sayCatName(); // => 'Mew' | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function MyCat(name) { | |
| this.catName = name; | |
| } | |
| MyCat.prototype.sayCatName = () => { | |
| console.log(this === window); // => true | |
| return this.catName; | |
| }; | |
| var cat = new MyCat('Mew'); | |
| cat.sayCatName(); // => undefined | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var calculate = { | |
| array: [1, 2, 3], | |
| sum() { | |
| console.log(this === calculate); // => true | |
| return this.array.reduce((result, item) => result + item); | |
| } | |
| }; | |
| calculate.sum(); // => 6 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var calculate = { | |
| array: [1, 2, 3], | |
| sum: () => { | |
| console.log(this === window); // => true | |
| return this.array.reduce((result, item) => result + item); | |
| } | |
| }; | |
| console.log(this === window); // => true | |
| // Throws "TypeError: Cannot read property 'reduce' of undefined" | |
| calculate.sum(); |