A drop of JavaScript - A subset of ECMAScript 2020 implemented in FreePascal
- Variables:
let
andconst
declarations (novar
) - Functions: Arrow functions only (no
function
keyword) - Loops: No traditional loops - use array methods instead
- Equality: Triple equals (
===
) only - Strict Mode: Implicit (no need to declare)
- No
eval
: For security - No
arguments
: Simplified argument handling due to not having an ES3-likefunction
- Template strings
- Object shorthands
Math.clamp
- Private fields and methods in classes
class CoffeeShop {
#name = "Goccia Coffee";
#beans = ["Arabica", "Robusta", "Ethiopian"];
#prices = { espresso: 2.5, latte: 4.0, cappuccino: 3.75 };
getMenu() {
return this.#beans.map((bean) => `${bean} blend`);
}
calculateTotal(order) {
return order.reduce((total, item) => total + (this.#prices[item] ?? 0), 0);
}
get name() {
return this.#name;
}
}
const shop = new CoffeeShop();
const order = ["espresso", "latte"];
const total = shop.calculateTotal(order);
console.log(`Welcome to ${shop.name}!`);
console.log(`Your order total: $${total.toFixed(2)}`);
- Module system
- HMR
- Performance tests
- Explicitness: Modules, classes, methods and properties are exlicit even at the cost long names. Shortcuts are typically avoided.
- OOP over everything: Rely on type safety of specialised classes
Define
vsAssign
: Explicitly defines a variable, assign re-assigns the value