The let()
function will allow you to assign a value to a variable, and then use that variable in the expression.
let(variable, value, expression)
Code language: JavaScript (javascript)
Note that the resulting variable can only be used between the parentheses of the original let()
function, not outside of them.
let()
, along with its big brother lets, is one of the most useful functions in Notion’s formula language. Here are a few of its primary uses:
- Define a variable with complex logic, then reference it in multiple places throughout a formula
- Separate formula logic from display (e.g. using variables when constructing final string values)
- Access the
current
variable of an outer List function within an inner List function (e.g.map(filter())
Example Formulas
/* A simple example */
let(
lastItem,
["Luffy", "Zoro", "Nami", "Usopp"].last(),
lastItem + " is the most recent addition to the crew."
)
/* Output: Usopp is the most recent addition to the crew. */
/* let() is also good for accurately setting plurality */
let(
plurality,
if(
prop("Owned Books") == 1,
"",
"s"
),
"I own " + prop("Owned Books") + " book" + plurality
)
/* Sample Outputs: "I own 1 book", "I own 24 books" */
/* Complex logic (a birthday calculation) is saved in a variable */
let(
birthdayThisYear,
(now().year() + "-" + prop("Birthday").formatDate("MM-DD")).parseDate(),
birthdayThisYear.dateAdd(
if( today() > birthdayThisYear, 1, 0 ),
"years"
)
)
/* Output (assume Birthday prop value is December 14, 1994 and today is March 20, 2025): Dec 14, 2025 */
Code language: JavaScript (javascript)
A variable defined in an outer instance of let()
can be used within an inner instance of let()
. However, if the inner instance has a variable of the same name, the outer one will be overridden in that inner context.
let(
firstName, "Monkey",
let(
lastName, "Luffy",
firstName + " D. " + lastName
)
)
/* Output: Monkey D. Luffy */
/* An inner variable will override an outer variable of the same name. */
let(
lastName, "Luffy",
"Monkey D. " + let(
lastName, "Garp",
lastName
)
)
/* Output: Monkey D. Garp */
Code language: JavaScript (javascript)
You can see more detailed examples, along with an example database, in the article for lets()
:
