Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 1.66 KB

write-modern-js.md

File metadata and controls

46 lines (34 loc) · 1.66 KB

Item 79: Write Modern JavaScript

Things to Remember

  • TypeScript lets you write modern JavaScript whatever your runtime environment. Take advantage of this by using the language features it enables. In addition to improving your codebase, this will help TypeScript understand your code.
  • Adopt ES modules (import/export) and classes to facilitate your migration to TypeScript.
  • Use TypeScript to learn about language features like classes, destructuring, and async/await.
  • Check the TC39 GitHub repo and TypeScript release notes to learn about all the latest language features.

Code Samples

function Person(first, last) {
  this.first = first;
  this.last = last;
}

Person.prototype.getName = function() {
  return this.first + ' ' + this.last;
}

const marie = new Person('Marie', 'Curie');
console.log(marie.getName());

💻 playground


class Person {
  constructor(first, last) {
    this.first = first;
    this.last = last;
  }

  getName() {
    return this.first + ' ' + this.last;
  }
}

const marie = new Person('Marie', 'Curie');
console.log(marie.getName());

💻 playground