Variables
The video for “Variables” is in the works!
Variables store data that your program can use and modify.
Declaring Variables
Mux has explicit typing with type inference. You can declare variables with explicit types or let Mux infer the type:
When to Use Explicit Types
The auto keyword works well when the type is obvious from the value:
auto name = "Mux"- string inferredauto count = 42- int inferredauto numbers = [1, 2, 3]- type inferred from contents
Some cases require an explicit type because the type can't be inferred:
- Empty collections:
auto empty = [](error - can't infer element type) - Use explicit types:
List<int> numbers = [],Map<string, int> ages = {}
Constants
Use const to declare values that never change:
Incrementing and Decrementing
Variables can be incremented or decremented using ++ and --:
Previous: Hello World | Next: Basic Types