0Pricing
Mojo Academy · Lesson

Declaring Values with var

Create named variables in Mojo.

Declaring Values with var 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.

Why You Need Names

A program juggles many values. To reuse one later you give it a name. In Mojo you create a named value with var. 📦

Your First var

Write var, then a name, then = and a value. Mojo stores the value under that name so you can use it again.

var score = 100

Reading the Value Back

Once declared, use the name anywhere you want that value. Here score stands in for 100 when you print it.

var score = 100
print(score)

Names Hold Things You Compute

A var does not have to be a literal. You can name the result of an expression so the math happens once.

var total = 100 + 50
print(total)

Changing a var Later

A var is mutable: assign a new value any time without repeating var. The name simply points at its latest value.

var score = 100
score = 250

Choose Clear Names

Good names describe the value. Prefer user_age over x so your code reads like plain English later.

var user_age = 30

snake_case Style

Mojo names use lowercase words joined by underscores, called snake_case. It matches Python and keeps code tidy.

var first_name = "Ada"

Declare Before You Use

You must create a name before reading it. Using a name Mojo has never seen is an error, which catches typos early.

One Name, One Value at a Time

A var holds a single value. Reassigning replaces the old one entirely, so the previous value is simply gone.

var mode = "easy"
mode = "hard"

var Inside a Function

Most vars live inside a function. They exist while the function runs and describe that function's local work.

fn main():
    var greeting = "hi"
    print(greeting)

var Makes Code Readable

Naming a value once and reusing it beats retyping the same number. A clear var is documentation that runs.

Quick Check

You want to store a number so you can reuse it later in your code. Which keyword declares it?

Recap

Use var to name a value, read it by name, and reassign it later. Clear snake_case names make your code easy to follow. 🎯

Frequently asked questions

Is the “Declaring Values with var” lesson free?

Yes — the full text of “Declaring Values with var” 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 “Declaring Values with var”?

Create named variables in Mojo. 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 “Declaring Values with var” 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

  1. Declaring Values with var
  2. Int, Float, and Bool
  3. Strings and Text
  4. Type Annotations That Help
← Back to Mojo Academy