StoicBuilder

HandbookI the LudusData types

Ithe Ludus, Read code

Data types

1 min readUpdated 28 November

In plain words

Every value has a type, such as a string (text), a number or a boolean (true or false), and the type decides what you can do with it.

Where you see it

Someone types 2 into QuickBite's quantity box, the code adds 1, and the cart shows 21. Form fields always hand your code text, so "2" + 1 glues the characters together instead of adding them.

src/components/QuantityPicker.tsxbrowser
// input values always arrive as stringsconst raw = event.target.value; // "2"const wrong = raw + 1; // "21"const right = Number(raw) + 1; // 3
It looked like a number. Its type said text.

What goes wrong

  1. Adding numbers that are secretly strings

    Values from forms, URLs and some APIs arrive as text. The plus sign then joins them instead of adding, and totals grow extra digits.

    "10" + 5 // "105"
  2. Storing money as decimals

    JavaScript can't hold some decimals exactly, so small errors creep into totals. Store prices as whole cents and divide only for display.

    0.1 + 0.2 // 0.30000000000000004
  3. Saving "false" as text

    The string "false" isn't empty, so code treats it as true. A setting stored this way can never be switched off.

    if ("false") { /* this still runs */ }

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Find every place the checkout form's values are used and convert them to numbers before any maths. Store prices as whole cents, and list any value that was text when it should have been a number.

Quick check

Sign in to earn +10 XP for it

A Chirp post with 9 likes shows 91 after one more like. What happened?

Got a prompt that touches data types?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.