> For the complete documentation index, see [llms.txt](https://my-organization-23.gitbook.io/solidity-basic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://my-organization-23.gitbook.io/solidity-basic/constanttoimmutable.md).

# constantとimmutable

constantとimmutableは変数の属性を定義し、定数として利用できます。

`constant`：代入を許可せず（初期化を除く）、ストレージスロットを占有しないのでガスの節約になります。

```solidity
contract ConstantContract {
    address public constant NEW_ADDRESS = 0xABCDEF0123456789ABCDEF0123456789ABCDEF01;
    uint public constant NEW_UINT = 987;
}
```

`immutable`：constructor内で代入を許可し、デプロイされた時点で定数です。コードに格納されます。

```solidity
contract ImmutableContract {
    address public immutable NEW_ADDRESS;
    uint public immutable NEW_UINT;

    constructor(uint _newUint) {
        NEW_ADDRESS = msg.sender;
        NEW_UINT = _newUint;
    }
}
```
