# Variable declarations within let blocks

**URL:** https://discourse.julialang.org/t/variable-declarations-within-let-blocks/29882
**Category:** General Usage
**Created:** [October 14, 2019, 2:10am UTC](https://discourse.julialang.org/t/variable-declarations-within-let-blocks/29882 "2019-10-14T02:10:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)
#### Post date: [October 14, 2019, 2:10am UTC](https://discourse.julialang.org/t/variable-declarations-within-let-blocks/29882/1 "2019-10-14T02:10:33Z")

</div>

Is there any semantic difference between the following two forms?

```julia
let a = 2, b = 3
    a + b
end

```

and

```julia
let
    a = 2
    b = 3
    a + b
end

```

I’m specifically curious about whether these are equivalent with respect to assignments that introduce new variables. I am working on a macro which currently expands to the latter.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [October 14, 2019, 2:28am UTC](https://discourse.julialang.org/t/variable-declarations-within-let-blocks/29882/2 "2019-10-14T02:28:34Z")

</div>

```julia
julia> function f1()
           a = 1
           b = 2
           let a = 2, b = 3
           end
           return (a, b)
       end
f1 (generic function with 1 method)

julia> function f2()
           a = 1
           b = 2
           let
           a = 2; b = 3
           end
           return (a, b)
       end
f2 (generic function with 1 method)

julia> f1()
(1, 2)

julia> f2()
(2, 3)

```

`let` creates a new local scope and similar to other form of local scope (loops and with slight difference, `functions`) you can create new local variables or override nested local variables in them.

The special feature of `let` is that you can specify local variables that is not inherited from the parent local scope, when you specify them in the argument of `let`.

---

<div class="post-metadata">

### Author: ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)
#### Post date: [October 14, 2019, 2:31am UTC](https://discourse.julialang.org/t/variable-declarations-within-let-blocks/29882/3 "2019-10-14T02:31:11Z")

</div>

Thank you, Yichao. I just realized that I was not seeing this difference due to testing in global scope.
