📖JSDoc
/** <-- ⭐️ JSDoc expects two stars (no more, no less)
*
*//**
* Adds VAT to a price
*
* @param {number} price The price without VAT
* @param {number} vat The VAT [0-1]
*
* @returns {number}
*/
function addVAT(price, vat = 0.2) {
return price * (1 + vat)
}// defining objects
/**
* @typedef {Object} Article
*
* @property {number} price
* @property {number} vat
* @property {string} string
* @property {boolean=} sold (⭐️ optional property)
*/
// ⭐️ optional property/parameter syntax:
// • @param {boolean=} sold
// • @param {boolean} [sold]
/**
* Now we can use `Article` as a proper type
*
* @param {[Article]} articles
*/
function totalAmount(articles) {
return articles.reduce((total, article) => {
return total + addVAT(article) }, 0)
}Last updated