I understand that function declarations are hoisted to the top of their scope. This allows us to use those functions before they're actually declared in JavaScript:

```
sayHello(); // It works!

function sayHello() {
  console.log('Hello');
}

```

I also understand that closures enable functions to retain references to variables declared within the same scope:

```
function outerFxn() {
  let num = 0;

  function innerFxn() {
    console.log(num);
    num++;
  }

  return innerFxn;
}

const logNum = outerFxn();
logNum(); // 0
logNum(); // 1
logNum(); // 2

```

So far so good. But here's some weirdness that I'm hoping someone can explain exactly what's going on...

Scenario 1: understandable closure
----------------------------------

```
function zero(cb) {
  return setTimeout(cb, 0);
}

function test1() {
  let txt = 'this is a test message';

  function log() {
    console.log(txt);
  }

  zero(log);
}

```

In the example above, the `log` function retains a reference to the scope in which it was created, holding on the the `txt` variable. Then, when executed later on in the `setTimeout`, it successfully log's the `txt` variable's value. Great. Then there's this...

Scenario 2: what is happening?
------------------------------

```
function zero(cb) {
  return setTimeout(cb, 0);
}

function test1() {
  function log() {
    console.log(txt);
  }

  let txt = 'this is a test message';

  zero(log);
}

```

I've moved the `log` function declaration to the top of the scope (it would have been hoisted there anyway, right?), *then* I'm declaring the `txt` variable below it. This all still works and I'm not sure why. How is `log` retaining a reference to the `txt` variable when `let`'s and `const`'s aren't hoisted up? Are closure scopes analyzed *as-a-whole*? I could use a bit of clarity on what the JavaScript engine is doing step by step here. Thank you SO land!