Data types tell your code what kind of value it's working with — and what that value can do. Pick the wrong one and things crash, slow down, or just produce weird results. Pick the right one and the rest of your code stays readable and clean.
Click any type to see how it shows up in a game.
Data
Type
Number
String
Boolean
Array
Object

Pick a type above to see what it stores.

  1. Number. Anything you'd write as a numeric value — health, speed, position, frame count. Example: velocity: 3. Used for physics, damage math, timers, and pretty much anything that changes over time.
  2. String. Text in any form — names, modes, file paths, dialogue. Example: "hostile". Used for NPC states, sprite paths, UI labels, and item or quest IDs.
  3. Boolean. A simple yes/no switch — only ever true or false. Example: isPaused: true. Used for any binary game state: isJumping, isAlive, isAttacking, pause flags, visibility toggles.
  4. Array. An ordered list of similar items. Example: gameObjects[]. Used for collections — every enemy on screen, every bullet in flight, every inventory slot.
  5. JSON Object. A bundle of named properties grouped together. Example: { hitbox: { width: 40 } }. Used for anything with more than one piece of info: NPC configs, level definitions, save files, dialogue trees.
Click a type to switch tabs.

Number

Numbers cover anything that ticks, counts, or measures.

velocity: 3

Physics, health, movement speed, animation timing, hit detection — if it changes frame by frame, it's a number.

String

Strings hold text — labels, modes, identifiers.

state: "hostile"

NPC behavior modes, sprite paths, dialogue, item and quest IDs all live as strings.

Boolean

The simplest type in the language. Just true or false — nothing else.

isPaused: true

Game loop control, AI flags, visibility toggles, invincibility frames, input handling — anything that has only two states.

Array

An ordered list of values, usually all of the same kind.

gameObjects[]

Every active sprite, every enemy or bullet group, particle effects, inventory slots, level layouts.

JSON Object

A bundle of related properties grouped under one name.

{ hitbox: { width: 40, height: 60 } }

NPC configs, level definitions, save files, game settings, dialogue trees.

If you need to store…
Use
A count, position, or measurement
Number
A name, mode, or file path
String
A yes/no state
Boolean
A collection of similar things
Array
A thing with many properties
JSON Object
  • Watch the "true" vs true trap — one is a string, the other is a boolean. They look identical but behave totally differently in logic checks.
  • Numbers do math; strings concatenate. "5" + 3 gives "53", not 8.
  • Arrays are best when all items are similar; objects are better when each property is different.
  • A JSON object doesn't have to come from a file — it's just a way of bundling named values.