> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/NormandoRamirezDelgado/6C-Febrero-2026/llms.txt
> Use this file to discover all available pages before exploring further.

# Variables

> Learn how to declare and name variables properly in Dart

## Introduction

Variables are containers that store data values in your program. In Dart, you can use the `var` keyword for type inference, where Dart automatically determines the variable's type based on the value assigned to it.

## Declaring Variables with var

Dart uses **type inference** when you declare variables with `var`. The compiler automatically determines the type based on the initial value:

```dart theme={null}
void main() {
  var edad = 18;                      // Inferred as int
  var nombre = 'Juan';                // Inferred as String
  var curp = 'GAFS081201HTSMLNB3';   // Inferred as String
  var estadoCivil = true;             // Inferred as bool
  var apellido_paterno = 'Ruíz';     // Inferred as String
  
  print(edad);              // 18
  print(curp);              // GAFS081201HTSMLNB3
  print(nombre);            // Juan
  print(estadoCivil);       // true
  print(apellido_paterno);  // Ruíz
}
```

## Variable Naming Best Practices

<Warning>
  Following proper naming conventions is crucial for writing clean, maintainable code.
</Warning>

### Good Variable Names ✓

Variable names should be:

* **Descriptive**: Clearly indicate what the variable stores
* **Complete**: Use full words, avoid abbreviations
* **Lowercase**: Start with a lowercase letter
* **CamelCase**: Use camelCase for multi-word names

```dart theme={null}
// Good examples
var edad = 18;
var nombre = 'Juan';
var curp = 'GAFS081201HTSMLNB3';
var estadoCivil = true;
var apellido_paterno = 'Ruíz';
```

### Bad Variable Names ✗

<Warning>
  Avoid these naming patterns - they make your code hard to read and maintain:
</Warning>

```dart theme={null}
// BAD: Single letters - not descriptive
var a = 10;
var c = 'Luisa';

// BAD: Abbreviated names - unclear meaning
var num = 8;
var num1 = 56;
var numero1 = 7;

// This code is confusing!
print(a + num + num1 + numero1);  // What does this calculate?
print(c);                          // What does 'c' represent?
```

## Why Good Naming Matters

<CardGroup cols={2}>
  <Card title="Readability" icon="book-open">
    Code is read more often than it's written. Descriptive names make your code self-documenting.
  </Card>

  <Card title="Maintainability" icon="wrench">
    Clear names make it easier to update and debug your code months or years later.
  </Card>

  <Card title="Collaboration" icon="users">
    Other developers (and future you) will understand your code without extensive comments.
  </Card>

  <Card title="Fewer Bugs" icon="bug">
    Descriptive names help prevent mistakes and make errors easier to spot.
  </Card>
</CardGroup>

## Naming Convention Rules

<Accordion title="Variable Names">
  * Start with a lowercase letter
  * Use camelCase for multiple words: `firstName`, `userAge`, `isActive`
  * Can contain letters, numbers, and underscores
  * Cannot start with a number
  * Cannot use Dart reserved keywords
</Accordion>

## Complete Example

Here's a comparison showing the difference between good and bad variable naming:

```dart theme={null}
void main() {
  // ❌ BAD: What do these represent?
  var a = 25;
  var b = 'Smith';
  var c = true;
  
  // ✅ GOOD: Clear and descriptive
  var employeeAge = 25;
  var employeeLastName = 'Smith';
  var isEmployeeActive = true;
  
  // The good names make the code self-explanatory
  if (isEmployeeActive && employeeAge >= 18) {
    print('$employeeLastName is an active adult employee');
  }
}
```

<Tip>
  When choosing variable names, ask yourself: "Will I understand what this variable represents if I read this code in 6 months?"
</Tip>

## Key Takeaways

* Use `var` for type inference when the type is obvious from the assigned value
* Always use descriptive, complete variable names
* Follow camelCase naming convention
* Avoid single letters, abbreviations, and numbered suffixes like `num1`, `num2`
* Write code that reads like natural language

## Next Steps

Now that you understand how to declare and name variables, let's explore the different data types available in Dart.
