Clamps number within the inclusive lower and upper bounds. Part of Lodash Number (stable since 4.0.0 — not deprecated). Too small → lower; too large → upper; otherwise unchanged.
Pass the numbers shown below. Check bounds and return type before you use the result.
Syntax
Call _.clamp. Start with this line.
Lodash
_.clamp(number, lower, upper)
Call
What it does
_.clamp(number, lower, upper)
Primary signature.
_.clamp(number, [lower], upper)
Work with a number and its bounds.
Prefer import clamp from "lodash/clamp" when you want a smaller bundle.
_.clamp is a Lodash Number helper available since 4.0.0. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native engines also offer Math.min(upper, Math.max(lower, n)) when bound order is known.
✓ Stable · Lodash 4.x
_.clamp()
Available in [email protected] full builds and the lodash/clamp modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.clampSince 4.0.0
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import clamp from "lodash/clamp" for smaller builds. Keep lower ≤ upper.
Frequently Asked Questions
_.clamp(number, lower, upper) clamps number within the inclusive lower and upper bounds. Official docs: _.clamp(-10, -5, 5) → -5 and _.clamp(10, -5, 5) → 5.
It is returned unchanged. For example _.clamp(0, -5, 5) → 0.
Lodash does not swap them. Bounds are applied as given (upper first, then lower), so reversed arguments can surprise you. Normalize with Math.min / Math.max when order is unknown.
Only when lower ≤ upper. Prefer Math.min/Math.max on the bounds first if users can pass them in either order.
_.clamp returns a number forced into the range. _.inRange returns a boolean — whether a value sits in a half-open range.
Use import clamp from "lodash/clamp" or require("lodash/clamp") so bundlers can tree-shake. Full build: import _ from "lodash" then _.clamp.