---
title: "Clamp a value inside a range"
description: "Restrict a value to lie within a specified range in TypeScript."
date: "2025-10-02"
tags: ["typescript","math","range","frontend"]
canonical: "/snippets/typescript/number/range"
---

import { Code } from '@astrojs/starlight/components'
import Source from './range.ts?raw'

## Clamp a value inside a range

<Code code={Source} lang="ts" title="range.ts" wrap />
