Addition in Pug-and-Express work is done in three distinct places—JavaScript values prepared in the Express route, arithmetic/computed values written inside Pug, and concatenation or conditional insertion handled by Pug syntax—and the phrase "is done" is ambiguous precisely because Pug is a template engine, not a language where you normally perform general arithmetic as a matter of course. Before treating the job as finished, you should decide which of those three meanings you intend, because each has different syntax, different failure modes, and different implications for escaping, runtime errors, and maintainability.
What "addition" can mean in a Pug + Express project
Pug (formerly Jade) is a server-side templating language for Node.js. Express is the web framework that typically renders Pug via res.render. The combination means a .pug file is compiled to a JavaScript function that receives a locals object. That object is built from res.locals, app.locals, and the object you pass to res.render (in that order of precedence, with the render object winning).
"Addition" in that pipeline almost always refers to one of these:
1: Arithmetic addition of numbers, e.g. a + b. 2: String concatenation, e.g. building "Hello, " + name. 3: Insertion of content into the template, i.e. adding a block, partial, mixin, attribute, or variable into the markup. 4: Incremental addition across a list, e.g. summing array values or appending to an HTML fragment.
Treating these as interchangeable is the most common source of confusion. Pug's unescaped interpolation, its buffered code (- and =) and its unbuffered code (-) behave differently with respect to escaping and side effects, and Express decides which values even reach the template.
Arithmetic addition inside Pug
Pug supports JavaScript expressions after = (buffered output) and after - (unbuffered code). A minimal, correct example:
The expression price + tax is evaluated at render time. The #{} syntax escapes the result for HTML, so a numeric sum like 21.59 is inserted safely. Note two hazards:
Floating point. 19.99 + 1.60 in JavaScript is 21.590000000000003 on most engines, not 21.59. If exact money values matter, handle currency in integer minor units (cents) or with a decimal library in the route handler, not in the template. Type coercion. If price arrives as a string (e.g. from a query parameter), "19.99" + 1.60 yields "19.991.6" — string concatenation, not addition. The template does not throw; it silently produces nonsense. This is the most common "why is my addition wrong" bug in Pug.
#{} is interpolated and escaped by default. !{} is interpolated and not escaped. For numeric expressions escaping is a no-op, but for concatenated strings the distinction matters: !{'' + label + ''} injects markup, while #{'' + label + ''} shows the literal tags. Prefer building trusted markup in Pug syntax and reserving !{} for values you thoroughly trust.
Buffered versus unbuffered code and what "done" implies
The = and #{} forms buffer output into the rendered HTML. The - form executes code but emits nothing. Therefore:
is functionally equivalent to p Total: #{price + tax} for output, but the unbuffered version lets you add a value once and reuse it. A subtlety: - inside a template runs at render time and can mutate locals, but it does not add anything to the response by itself. If a learner says "I added the numbers and nothing appeared," it is usually because they used - total = price + tax (silent) rather than = total or #{total} (visible).
Another common mismatch: - with