What each value on the page means
| On the page | What produced it | Where to look |
|---|---|---|
undefined, null | A missing or empty field turned into text | A field the API renamed, left out or sent as null |
NaN, $NaN | Math on something that is not a number | A missing quantity, or a price string such as "1,299.00" |
[object Object] | An object turned into text | A whole object, such as an error body, where one field was meant |
Invalid Date, NaN:NaN | A date made from a value that could not be parsed | A date string in a format the spec does not define, or undefined |
{{ name }} | A template that was never rendered | A script that failed to load or threw before the app mounted |
undefined and null: a missing field in a string
A template literal, or + with a string on one side, turns each value into a string, so a missing field becomes the word itself. When the API renames firstName to first_name or drops a field, the page says so:
const user = await res.json(); // { "first_name": "Ada", "plan": null }
`Hi ${user.firstName}` // "Hi undefined"
"Plan: " + user.plan // "Plan: null"
'Hi ${user.first_name}' // "Hi ${user.first_name}": quotes, not backticks
Only backticks make a template literal, so in quotes the placeholder is printed as written.
For a field that may be missing, set the default where you render it with ??, which replaces only null and undefined. || also replaces 0 and the empty string, so a real price of 0 would show your default (MDN).
`Hi ${user.firstName ?? "there"}`
A field that must always be there needs a check at the boundary instead (below).
[object Object]: an object printed as text
When JavaScript needs a string and gets an object, it calls the object's toString(), and for a plain object that returns "[object Object]" (MDN). Template literals, + with a string, String() and textContent all do it, and an array of objects prints [object Object],[object Object]. For example, an error body:
const body = await res.json(); // { "error": { "code": "card_declined", "message": "Your card was declined." } }
`Payment failed: ${body.error}` // "Payment failed: [object Object]"
`Payment failed: ${body.error.message}` // "Payment failed: Your card was declined."
console.log(JSON.stringify(body.error)); // to see what the object holds
Print the field you meant, and keep JSON.stringify for logs.
NaN: math on something that is not a number
NaN is what a failed number conversion gives: Number(undefined) is NaN, and so is a string that does not parse as a number, such as "1,299.00" (MDN). Math with NaN usually gives NaN (MDN), so one cart line with no quantity makes the whole total NaN:
const total = items.reduce((sum, i) => sum + i.price * i.qty, 0);
"$" + total.toFixed(2) // "$NaN" when one item has no qty
Number(null) // 0
Number("") // 0
parseFloat("1,299.00") // 1: it stops at the comma
The last three give numbers that look real: a price sent as null or "" shows as $0.00, and "1,299.00" read with parseFloat shows as $1.00. Convert numbers once where the data arrives and test them with Number.isFinite(), which is false for NaN, Infinity and non-numbers and converts nothing first (MDN).
Invalid Date: a date string that could not be parsed
The spec defines one format every browser must parse: the date time string format, a simplified ISO 8601 such as 2026-12-05T14:30:00Z (MDN). Other formats are left to each browser (MDN). When parsing fails, the date's time value is NaN and its string form is Invalid Date (MDN). Its hours and minutes are NaN too, so a time built from them reads NaN:NaN.
new Date("2026-12-05T14:30:00Z") // parses in every browser
new Date("31/12/2026") // Invalid Date in Chromium and Node: day first
new Date(undefined) // Invalid Date
Number.isNaN(new Date(value).getTime()) // true for an invalid date
Two more traps, checked in Chromium 159 and Node 22. new Date(null) is a valid date, time 0, so a missing date shows as a real one: 1 January 1970, or 31 December 1969 west of UTC. And Intl.DateTimeFormat's format() uses the current time for undefined (ECMA-402), so a missing date shows today, and it throws a RangeError for an invalid date or a date string (ECMA-402). Send dates in the ISO format with Z or an offset (without one, a date with a time is read as local time), or as epoch milliseconds, and check getTime() before you format.
Raw {{ name }}: a template that never ran
Raw braces mean the code that should replace the template never ran. In Vue without a build step, in-DOM templates show raw mustache tags until the component mounts (Vue docs), and they stay if the script fails to load or throws first. AngularJS pages show the raw template while they load (ngCloak source). A server template (Jinja, Liquid, ERB) shows its tags when the file is served without the engine.
<style>[v-cloak] { display: none; }</style>
<div id="app" v-cloak>Hi {{ name }}</div>
v-cloak stays on the element until the component mounts, so this hides the flash while the app loads (AngularJS has ng-cloak). Neither helps an app that never mounts: the section stays hidden instead. If the braces stay after the page settles, find the script error in the console. For a page that renders nothing, see blank page in production.
Fix it once: check data at the boundary, format at the edge
The first four leaks start with data in a shape the code did not expect. Check it where it enters the app, and format every number and date in one place:
// Where API data enters the app: convert once, throw with the bad payload.
function toNumber(v) {
if (typeof v === "number") return v;
if (typeof v === "string" && v.trim() !== "") return Number(v);
return NaN; // undefined, null, "" and objects
}
export function parseOrder(raw) {
const order = { id: raw.id, total: toNumber(raw.total), placedAt: new Date(raw.placedAt ?? NaN) };
if (!Number.isFinite(order.total) || Number.isNaN(order.placedAt.getTime())) {
throw new TypeError(`Bad order from the API: ${JSON.stringify(raw)}`);
}
return order;
}
// Where values become text: one formatter each, with a fallback.
const money = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
const day = new Intl.DateTimeFormat("en-US", { dateStyle: "medium" });
export const formatPrice = (n) => (Number.isFinite(n) ? money.format(n) : "-");
export const formatDate = (d) =>
d instanceof Date && !Number.isNaN(d.getTime()) ? day.format(d) : "-";
parseOrder accepts 12.5 and "12.50", and throws for "1,299.00", an empty string, null, a missing total or a date it cannot parse. A bad value then throws instead of reaching the page.
Keep the check in each formatter: in Chromium 159 and Node 22, money.format(NaN) and money.format(undefined) return $NaN, and money.format(null) returns $0.00, so Intl.NumberFormat alone does not catch a missing value.
Catch leaks in a Playwright test
A test can feed the page a bad response and fail on any of these values. route.fulfill({ json }) answers a request with the JSON you write (Playwright docs), so you can leave out a field without touching the API:
import { test, expect } from "@playwright/test";
// Text no user should see. Remove a word your pages use on purpose.
const LEAKS = /\[object Object\]|Invalid Date|\bNaN\b|\bundefined\b|\bnull\b|\{\{.*?\}\}|\$\{.*?\}/g;
test("cart with a missing quantity shows no leaked values", async ({ page }) => {
await page.route("**/api/cart", (route) =>
route.fulfill({ json: { items: [{ name: "Mug", price: 12 }] } })); // no qty
await page.goto("/cart"); // baseURL from your config
await expect(page.getByText("Mug")).toBeVisible(); // the mocked data has rendered
const text = await page.locator("body").innerText();
expect(text.match(LEAKS) ?? []).toEqual([]);
});
On a test cart page that builds the total with "$" + total.toFixed(2), it fails and lists ["NaN"]; with formatPrice it passes. Before you read, wait for text that only the mocked response brings, such as the item name: the total may already show a placeholder, and an auto-retrying assertion such as not.toContainText() passes as soon as the text is clean (Playwright docs), which can be before the bad value arrives. innerText skips hidden elements, scripts and styles, which textContent includes (MDN). If your pages show code samples, read a narrower locator than body.
Where GenClass fits
GenClass Runtime (@genclass/runtime) has a measured visual check for this, text-template-leak. It reads the page's visible text and reports [object Object], Invalid Date, unrendered template syntax ({{ name }}, ${name}, {% if %}, <%= name %>), NaN:NaN, and NaN, undefined or null next to a currency sign or unit ($NaN, NaN%), if the text is still there 2 seconds later and after the network goes quiet. It is a fixed pattern match, reported as a check and never as a model finding, and it changes nothing on the page.
It does not report text that is only undefined, null or NaN, a sentence such as Hi undefined, or $0.00 for a missing price, and it skips code samples and form fields. On two forms the checks' author planted, [object Object] and $NaN, in demo, template and compatibility apps, in Chromium, it found 54 of 54, and the visual checks made 0 false reports in 128 page views of the same apps without faults. The false-report rate on other sites is not known (visual checks).
Once the runtime is in your app (npx genclass adds it), the check runs by default on development hosts such as localhost:3000 and prints a line starting [GenClass] Check (measured) in the console. It is off on public sites unless you turn it on.
Questions
Why does my page show [object Object]?
Your code turned a whole object into text, and that is how a plain object prints. Print the field you meant, such as error.message.
How do I check if a date is invalid in JavaScript?
Number.isNaN(date.getTime()) is true for an invalid date. Check it before you format, because Intl.DateTimeFormat throws a RangeError for one.
Why does a date string work in one browser and not another?
Only the ISO date time string format, such as 2026-12-05T14:30:00Z, must parse in every browser, and other formats are up to each one. Send that format with Z or an offset, or epoch milliseconds.
Why does my cart total show NaN?
One value in the sum was not a number, such as a missing quantity or a price string with a comma. Convert prices once when the data arrives and check them with Number.isFinite().
How do I stop Vue from showing curly braces before it loads?
Put v-cloak on the root element with the CSS rule [v-cloak] { display: none }, which hides it until the app mounts. If the braces stay, the app did not mount, so look for a script error.
Related: front-end bugs that raise no error, horizontal scroll on mobile and testing race conditions with Playwright.