# \`let x\` without assignment (\`let x = 1\`)

**URL:** <https://discourse.julialang.org/t/let-x-without-assignment-let-x-1/95297>\
**Category:** General Usage\
**Created:** [February 28, 2023, 1:10am UTC](https://discourse.julialang.org/t/let-x-without-assignment-let-x-1/95297 "2023-02-28T01:10:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [February 28, 2023, 1:10am UTC](https://discourse.julialang.org/t/let-x-without-assignment-let-x-1/95297/1 "2023-02-28T01:10:51Z")

</div>

Example from [Let Blocks](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#Let-Blocks)

```julia
var1 = let x
       display(@isdefined x) #false
           for i in 1:5
               (i == 4) && (x = i; break)
           end
           x
       end

```

we see that `x` is undefined before the assigned in `for` block. However

```julia
var1 = let 
       display(@isdefined x) #false
           for i in 1:5
               (i == 4) && (x = i; break)
           end
           x
       end

```

change `let x` to `let`, an error is fired. What does `let x` do actually?

Edit: from [topic:92211](https://discourse.julialang.org/t/syntax-how-to-write-a-cleaner-code-for-many-composed-computations/92211/12) (much thanks to [stevengj](https://discourse.julialang.org/u/stevengj) for the hints)

> The comma-delimited assignments in the “head” of the `let` statement behave differently from assignments in its body.
> 
> The behavior of `let` statements is like function definitions, where the head is like the argument list for a function with default values:

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 28, 2023, 1:34am UTC](https://discourse.julialang.org/t/let-x-without-assignment-let-x-1/95297/2 "2023-02-28T01:34:01Z")

</div>

A variable without an assignment declares a new local variable in a `let` block but does not give it a value.

This was recently clarified in the docs: [clarify `let x` without an assignment by stevengj · Pull Request #48122 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/48122)

See also the discussion here [Syntax: How to write a cleaner code for many composed computations - #12 by uniment](https://discourse.julialang.org/t/syntax-how-to-write-a-cleaner-code-for-many-composed-computations/92211/12)
