{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"redocly_category":"Journeys","product":"Identity Management","type":"markdown"},"seo":{"title":"Expressions: Let expressions","description":"Everything about Mosaic Journeys, SDKs, and APIs","siteUrl":"https://developer.transmitsecurity.com/","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"expressions-let-expressions","__idx":0},"children":["Expressions: Let expressions"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"_","__idx":1},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A let-expression is used when the result of a non-trivial computation should be used multiple times within an expression calculation. Let expressions take the following form:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"js","header":{"controls":{"copy":{}}},"source":"let name1=value1, ... return expression\n","lang":"js"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Names defined in the let section (such as ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["name1"]}," in the template above) assume the values assigned to them, and these names and their bound values are available for reference from within ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["expression"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["let r=@webrequests.getDetails(username) return r.body.firstName ? r.body.firstName : r.body.alias"]}," would invoke the web-request function ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["getDetails"]}," once, but will refer to the result several times throughout the computation."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Let-expressions may be nested. Defining or re-defining a variable in a let-expression is only in effect for the course of that let-expression's return expression evaluation (and not for the definition of subsequent variables in the let statement)."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example, in the expression ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["let a=1,... return (let a=9 return a)+a"]},", the returned value will be 10 as opposed to 18 (as would be the case if the second definition for ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["a"]}," would remain in effect until the end of the evaluation of the entire expression). Similarly, the expression ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["let a=1, ... return (let b=9 return a)+b"]}," will result in an error as ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["b"]}," is not defined outside the scope of the second let-expression."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A recursive-let expression is a variant of the let expression, where each variable definition can be used by subsequent variable definitions, in addition to the return expression. The syntax for a recursive-let expression is as follows:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"js","header":{"controls":{"copy":{}}},"source":"letr name1=value1, ... return expression\n","lang":"js"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following two expressions are equivalent:",{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]}," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["letr var1=val1, var2=val2 return expression"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["let var1=val1 return let var2=val2 return expression"]}]}]},"headings":[{"value":"Expressions: Let expressions","id":"expressions-let-expressions","depth":1},{"value":"","id":"_","depth":2}],"frontmatter":{"showNextButton":true,"showPrevButton":true,"seo":{"title":"Expressions: Let expressions"}},"lastModified":"2025-11-18T16:48:04.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/guides/orchestration/getting-started/expressions/let-expressions","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}