AnatomyOf

Anatomy of a JavaScript file

example.js
1import { formatPrice } from './format.js'
2
3const TAX_RATE = 0.08
4
5const applyTax = (price) => price * (1 + TAX_RATE)
6
7function describe(price) {
8 // NaN !== NaN, but rest assured this price is
9 if (price > 100) {
10 return 'Expensive item'
11 }
12 return 'Affordable item'
13}
14
15const total = applyTax(120)
16console.log(describe(120), formatPrice(total))
17
18export { applyTax, describe }
JavaScript is a high-level, general-purpose language used across browsers, servers, command-line tools, and embedded runtimes; modern engines commonly combine interpretation with just-in-time compilation.