A RegExp that marks tags whose contents are executed as JavaScript by _.template() (default <% ... %>). Part of Lodash Properties (stable in 4.x — not deprecated). Warning: never compile untrusted template strings — evaluate tags run code; Lodash plans to remove _.template in v5.
Set the property globally, or override it per call with options passed to _.template().
Syntax
Use _.templateSettings.evaluate. Start with this line.
Lodash
_.templateSettings.evaluate
Call
What it does
_.templateSettings.evaluate
Primary setting.
_.templateSettings.evaluate = /.../g
Assign a custom RegExp or value before compiling.
Prefer the full Lodash build when using _.template() and _.templateSettings.
Library declarations
Lodash
_.templateSettings.evaluate
Parameters
Parameter
Description
_.templateSettings.evaluate
Optional. (RegExp) Pattern for JS logic tags
Default pattern
Optional. (RegExp) /<%([\s\S]+?)%>/g
Capture group
Required. JavaScript source inside the tag
Return Value
Return Value
Description
*
RegExp (with a capturing group)
Lodash Examples
Example 1 — Official: Evaluate + Escape List
Evaluate tags run the loop; escape tags print each item safely.
Setup. Evaluate block initializes i and starts forEach.
Increment.i++ runs each iteration inside evaluate.
Print. Escape tags output the counter and item text.
Close. Final evaluate block ends the callback.
Compatibility
Browser & Runtime Support
_.templateSettings.evaluate ships with Lodash full builds (stable in 4.x). It configures _.template, which runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
Available on the [email protected] namespace. Works in evergreen browsers and current Node LTS when Lodash is installed. Treat _.template as legacy for untrusted template source.
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
.evaluateLodash 4.x
Bottom line: Use evaluate tags for loops and conditionals; print with escape/interpolate tags. Prefer per-call { evaluate } options over global mutation. Never compile untrusted template strings.
Frequently Asked Questions
It is a RegExp that tells _.template() which tags contain JavaScript to execute. The default matches <\x25 ... \x25> logic tags.
A RegExp. Lodash uses it at compile time to find control-flow blocks. Do not assign a callback to evaluate.
Interpolate tags (<\x25= \x25>) evaluate an expression and insert the result. Evaluate tags (<\x25 \x25>) run JavaScript for logic — loops, if/else, setup — without automatically printing a value.
Pair evaluate tags for the loop with escape or interpolate tags for output, e.g. <\x25 _.forEach(users, function(user) { \x25><li><\x25- user \x25></li><\x25 }); \x25>.
Yes. Pass { evaluate: /.../g } to _.template(string, options) to override _.templateSettings.evaluate for that compile only.
No. Compiling untrusted templates can execute code. Use only developer-controlled templates. Lodash plans to remove _.template in v5.