Item 79: Write Modern JavaScript
May 10, 2024 ยท View on GitHub
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());
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());