Table of contents
No headings in the article.
// Person: {
// name: string,
// age: number,
// }
to represent the 'shape' of a Person.
When you have functions like the following, you can use the shorthand to write the type of the input and output.
function getName(person) {
return person.name;
}
function getAge(person) {
return person.age;
}
function makePerson(name, age) {
return {
name: name,
age: age
};
}
function birthday(person) {
person.age += 1;
return person;
}
// Point: {
// x: number
// y: number
// name: string
//}
function getDistance(pointA, pointB) {
return Math.sqrt((pointA.x - pointB.x) ** 2 + (pointA.y - pointB.y) ** 2);
}