---
# System prepended metadata

title: Javascript

---

# Javascript

# Class
## Sub classing with `extends`
```
class Animal { 
  constructor(name) {
    this.name = name;
  }
  
  speak() {
    console.log(`${this.name} makes a noise.`);
  }
}

class Dog extends Animal {
  constructor(name) {
    super(name); // call the super class constructor and pass in the name parameter
  }

  speak() {
    console.log(`${this.name} barks.`);
  }
}

let d = new Dog('Mitzie');
d.speak(); // Mitzie barks.
```

# AJAX
## Promise
snippet of a function that returns a promise.
```
function tetheredGetNumber(resolve, reject) {
  try {
    setTimeout( 
      function() {
        const randomInt = Date.now();
        const value = randomInt % 10;
        try { 
          if(value >= THRESHOLD_A) {
            throw new Error(`Too large: ${value}`);
          } 
        } catch(msg) {
            reject(`Error in callback ${msg}`); 
        }
      resolve(value);
      return;
    }, 500);
    // To experiment with error at set-up, uncomment the following 'throw'.
    // throw new Error("Bad setup");
  } catch(err) {
    reject(`Error during setup: ${err}`);
  }
  return;
}
```


## async await
