Code Smell 86 - Mutable Const Arrays

Code Smell 86 - Mutable Const Arrays

Maxi Contieri
·Aug 25, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Const declares something to be constant. Can it mutate?

TL;DR: Don't rely on languages cheating about directives.


  • Unexpected side effects

  • Accidental complexity


  1. Use better languages.

  2. Use spread operator.

Sample Code


const array = [1, 2];


//array => [1, 2, 3]
//Wasn't it constant ?
//constant != immutable ?
const array = [1, 2];

const newArray = [...array,3 ]

//array => [1, 2] Didn't mutate
//newArray = [1, 2, 3]


Since this is a "language feature", we can explicitly forbid it.


  • Mutability

  • JavaScript


We should always favour immutability on our designs and take extra care with side effects.

More Info


Photo by Zorik D on Unsplash

Thank you, Oliver Jumpertz for this tip.

Correctness is clearly the prime quality. If a system does not do what it is supposed to do, then everything else about it matters little.

Bertrand Meyer

This article is part of the CodeSmell Series.

Share this


Technical Opinions are my own. I don't have the revealed truth.

Software Design is a creative activity. These are hints and not rigid rules.

I write on BackEnd Business Systems and OOP Design. My advice/experience might not suit other systems.

You can write me at info(at)