# Extract constant

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/go/llms.txt).

The Extract Constant refactoring makes your source code easier to read and maintain. It also helps you avoid usage of hardcoded constants without any explanation about their values or purpose.

<a id="extract_constant"></a>

Procedure:

1. In the editor, select an expression or declaration of a variable you want to replace with a constant.

2. Press [Introduce Constant… shortcut](https://www.jetbrains.com/help/go/llms-keymap-index.md "IntroduceConstant") to introduce a constant or select `Refactor | Extract | Constant` in the main menu.

> **Note:**
> By default, GoLand uses the in-place refactoring. To use the  dialog for the refactoring,           open the Settings dialog ([Settings… shortcut](https://www.jetbrains.com/help/go/llms-keymap-index.md "ShowSettings")), go to Editor | Code Editing, and select the In modal dialogs refactoring option in the Refactorings area.

3. Select an expression you want to extract as constant and press [Enter shortcut](https://www.jetbrains.com/help/go/llms-keymap-index.md "EditorEnter"). Select the number of occurrences you want to replace and a name you want to use.

[Video](https://resources.jetbrains.com/help/img/idea/2026.3/go_extract_constant.mp4)

[Code snippet at GitHub](https://github.com/apronichev/documentation-code-examples/blob/master/extractConstantVariable/main.go)

## See also

### External Links

