[Question]
  [
Imagine this short function to clamp a number between 0 and 255:
```
c = n => n > 0 ? n < 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.
  
[Answer]
# 20 bytes
For reference, this is the original version without whitespace and without naming the function:
```
n=>n>0?n<255?n:255:0
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1i7PzsA@z8bI1NQ@zwpIWhn8T87PK87PSdXLyU/XSNPQNTQy1tRUAAJ9fQUDLnRJiBRWSQOYHDZJQ2RJQ3RJA5hekKQBul6gMxHSQA6GtBk@aWNkw7Ho1tIyNgL7C7c0WD9E@j8A "JavaScript (Node.js) – Try It Online")
---
# 19 bytes
We can save a byte by inverting the logic of the ternary tests and using `n>>8` to test whether \$n\$ is greater than \$255\$. Because of the bitwise operation, this will however fail for \$n\ge 2^{32}\$.
```
n=>n<0?0:n>>8?255:n
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1i7PxsDewCrPzs7C3sjU1Crvf3J@XnF@TqpeTn66RpqGrqGRsaamAhDo6ysYcKFLQqSwShrA5LBJGiJLGqJLGsD0giQN0PUCnYmQBnIwpM3wSRsjG45Ft5aWsRHYX7ilwfqB0mmJmTnF/wE "JavaScript (Node.js) – Try It Online")
---
# 19 bytes
This one returns \$false\$ instead of \$0\$ but works for \$n\ge 2^{32}\$.
```
n=>n>255?255:n>0&&n
```
[Try it online!](https://tio.run/##fc/NCoQgEMDx@z5Fp6igGhX3EGTPEn2xS4xR0eubFVKYNeBh@PFH5l8u5VSNv2GOUdaNanOFuUBBOS/0y1CA76OqJE6yb5JedkEbxISyMPT0pKkHHxsPciIYcyG5IrERTLsh2C0F45q3xXbOz1wvN/6@Mbt@7qijiNH97mfe@4PVCg "JavaScript (Node.js) – Try It Online")
---
# 18 bytes
By combining both versions above, we end up with a function that works for \$256-2^{32}\le n<2^{32}\$ and returns \$false\$ for \$n<0\$.
```
n=>n>>8?n>0&&255:n
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1i7Pzs7CPs/OQE3NyNTUKu9/cn5ecX5Oql5OfrpGmgZQTNdIS8vYSFNTQV9fIS0xM6eYC12JGbISAzRpXUMjY6AMGGCVhklilTZAyGKTNkSVNkSXNkDoB0kbGGC43RRZAZCL6Tn8CoxRrcBiAihooL7ErQBqBiyI/wMA "JavaScript (Node.js) – Try It Online")
### Commented
```
n =>          // n = input number
  n >> 8 ?    // if n is greater than 255 or n is negative:
    n > 0 &&  //   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](https://codegolf.stackexchange.com/users/52194/value-ink) in the comments.)
---
# 17 bytes
We can go a step further by limiting the valid input range to \$-2^{24}< n\le 2^{24}\$:
```
n=>n>>8?-n>>>24:n
```
[Try it online!](https://tio.run/##fdDRCsIgFIDh@57CS13Y9GyLCGbPImvGQnRk9Pq2pLU0240g338UzlU@pOtuw3inxp57r1pvWmGEOJzodAqoj8Z31jir@522F6wwxVAUUBNCECpLpOSg3SZOOH0nKCQsYcqhCvaPZ8wyWzTHPGaeMlvmX8zSeWia72C6/gT79aCKv8i88FnOWrDl8/7Civ0T "JavaScript (Node.js) – Try It Online")
### Commented
```
n =>          // n = input number
  n >> 8 ?    // if n is greater than 255 or n is negative:
    -n >>> 24 //   non-arithmetic right-shift of -n by 24 positions
  :           // else:
    n         //   return n unchanged
```
]