Is it possible to make a clamp function shorter than a ternary in JS? Imagine this short function to clamp a number between 0 and 255:

c = n =&gt; n &gt; 0 ? n &lt; 255 ? n : 255 : 0


Is this the shortest possible version of a clamp function with JavaScript (without ES.Next features)?

P.S: Not sure if it's relevant but, the 0 and 255 are not random, the idea is to clamp a number as an 8-bit unsigned integer.
20 bytes
For reference, this is the original version without whitespace and without naming the function:

n=&gt;n&gt;0?n&lt;255?n:255:0

Try it online!

19 bytes
We can save a byte by inverting the logic of the ternary tests and using n&gt;&gt;8 to test whether \$n\$ is greater than \$255\$. Because of the bitwise operation, this will however fail for \$n\ge 2^{32}\$.

n=&gt;n&lt;0?0:n&gt;&gt;8?255:n

Try it online!

19 bytes
This one returns \$false\$ instead of \$0\$ but works for \$n\ge 2^{32}\$.

n=&gt;n&gt;255?255:n&gt;0&amp;&amp;n

Try it online!

18 bytes
By combining both versions above, we end up with a function that works for \$256-2^{32}\le n&lt;2^{32}\$ and returns \$false\$ for \$n&lt;0\$.

n=&gt;n&gt;&gt;8?n&gt;0&amp;&amp;255:n

Try it online!
Commented
n =&gt;          // n = input number
  n &gt;&gt; 8 ?    // if n is greater than 255 or n is negative:
    n &gt; 0 &amp;&amp;  //   return false if n is negative
    255       //   or 255 otherwise
  :           // else:
    n         //   return n unchanged

(This is a fixed revision of the code proposed by @ValueInk in the comments.)

17 bytes
We can go a step further by limiting the valid input range to \$-2^{24}&lt; n\le 2^{24}\$:

n=&gt;n&gt;&gt;8?-n&gt;&gt;&gt;24:n

Try it online!
Commented
n =&gt;          // n = input number
  n &gt;&gt; 8 ?    // if n is greater than 255 or n is negative:
    -n &gt;&gt;&gt; 24 //   non-arithmetic right-shift of -n by 24 positions
  :           // else:
    n         //   return n unchanged