# Effect, change of state

State change is a secondary effect generated by executing a [unit of code](https://blog.fiftywords.co/unit-of-code).

To validate the result we must access the state that has changed, so it is compromised of three steps:

- Execute the [unit of code](https://blog.fiftywords.co/unit-of-code)
- Access the changed state  
- Verify the value is as expected
  
```ts
/** State that is changed */
let currentValue = 0;

/** Unit of code that has an effect.
 * It changes currentValue
 */
function add(summand: number): void {
  /**
   * Exit point => Effect, Change of state
   */
  currentValue += summand;
}

/**
 * Way to access current state
 */
function getCurrentValue(): number {
  return currentValue;
}

/** Execute unit of code */
sumar(5);

/** Access changed state */
const valorAcumulado = obtenerValorActual();
/** Verify obtained value is what we expect */
valorAcumulado === 5;
```

[🇨🇴 Versión en Español](https://blog.cincuentapalabras.co/cambio-de-estado-punto-de-salida)
