What Value Semantics Means
Each variable owns its own value.
What Value Semantics Means is a free Mojo Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Mojo Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Two Ways to Think About Data
When you copy a value into a new variable, does each one stand alone, or do they secretly share? Value semantics answers that. 🤔
Each Variable Owns Its Value
Under value semantics, every variable holds its very own copy of the data. No two names quietly point at the same thing.
var a = 5
var b = aA Copy, Not a Link
Assigning b = a hands b a fresh copy. From that moment on, a and b live independent lives.
var a = 5
var b = a
print(a, b)Changing One Leaves the Other
Because b owns its own copy, updating b never touches a. The original value stays exactly as you left it.
var a = 5
var b = a
b = 99The Mental Model: Boxes
Picture each variable as its own box. Copying pours the contents into a second box, not a shortcut to the first.
Numbers Behave This Way
Simple types like Int copy by value naturally. Pass x around and each spot gets its own number to work with.
var x = 10
var y = x
y = 20Mojo Extends This to Your Types
Mojo applies value semantics broadly, even to structs you write. Copying a struct copies all of its fields too.
Why It Feels Predictable
With value semantics you read code locally: a variable changes only when you change it, never as a side effect elsewhere. ✅
Contrast With Sharing
The opposite is reference behavior, where two names point at one object. Mojo prefers values to avoid that surprise by default.
Independence Is the Big Idea
The heart of value semantics is independence: copies are truly separate, so edits stay contained where you make them.
var price = 100
var saved = price
price = 80It Powers Safe, Fast Code
Independent values let Mojo reason about your program tightly, which helps it stay both safe and fast.
Quick Check
You write var b = a, then change b. What happens to a under value semantics?
Recap
With value semantics, every variable owns an independent copy. Changing one never ripples into another, which keeps code predictable. 🎯
Frequently asked questions
Is the “What Value Semantics Means” lesson free?
Yes — the full text of “What Value Semantics Means” is free to read here on the web, and the Mojo Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Mojo Academy course, upgrade to CoddyKit PRO.
What will I learn in “What Value Semantics Means”?
Each variable owns its own value. You practise Mojo Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Mojo Academy?
No prior experience is required. Mojo Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “What Value Semantics Means” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Mojo Academy lesson?
Yes. Every Mojo Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What Value Semantics Means
- Copies vs Shared State
- Mojo's Safe Default
- A First Look at Mutation