Code Smell 84 - Max < Min (Javascript)

Code Smell 84 - Max < Min (Javascript)

Maxi Contieri
·Jul 20, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Some functions do not behave as expected. Sadly, most programmers accept them.

TL;DR: Don't trust max() and min() functions. Just ignore them.


  • Principle of least astonishment

  • Bijection Violation.

  • Unexpected Results


  1. Use mature languages.

  2. Avoid max() and min() functions.

  3. Model Infinites carefully.

Sample Code


console.log(Math.max() > Math.min());

//returns false


//returns -Infinite
console.log(Math.max() > Math.min());

//returns Exception. Not enough arguments passed.
//Max requires at least one argument


These functions belong to the standard Math library. Therefore, they are not easy to avoid.

We can block them on our linters.


  • Javascript


We need to be very careful using functions that violate real-world concepts using language tricks.


More Info


Photo by Cris Baron on Unsplash

Inspired by @Oliver Jumpertz

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

Rick Cook

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)