# Refactoring 006 - Rename Result Variables

> TL;DR: Use the last call as a semantic guide.

# Problems Addressed

- Bad naming on variables

# Related Code Smells

%[https://maximilianocontieri.com/code-smell-81-result]

%[https://maximilianocontieri.com/code-smell-79-theresult]

# Steps

1. Name the variable with the same name as the last function call.

# Sample Code

## Before

[Gist Url]: # (https://gist.github.com/mcsee/c4f1e90fb0a61724ea5993e04d572b5c)
```javascript
function doubleFavoriteNumber(n) {
    return this.favoriteNumber * n;
}

var result = doubleFavoriteNumber(2);

// Many lines after we have no idea what does 
// result holds

// var result ???
```

## After

[Gist Url]: # (https://gist.github.com/mcsee/5a9bbc54b45798a610f0a76b8c25a583)
```javascript
function doubleFavoriteNumber(n) {
    return this.favoriteNumber * n;
}

const favoriteNumberDoubled = doubleFavoriteNumber(2);

// Many instructions after

// We can use favoriteNumberDoubled knowing its semantics
```

# Type

[X] SemiAutomatic

As with many name heuristics, we can replace the variable with another refactor *rename variable*

# Why code is better?

A variable scope can last a lot.

Assignment and usage might be very far away from each other.

# Tags

- Naming 

# See also

[What is in a name?](https://maximilianocontieri.com/what-exactly-is-a-name-part-i-the-quest)

# Credits

Image by [HeungSoon](https://pixabay.com/users/heungsoon-4523762/) on [Pixabay](https://pixabay.com/)

* * * 

This article is part of the Refactoring Series.
