Question: How do I make sure that boo is defined before I call it?
I don't want to be forced to rearranging my JavaScript such that `boo = function` is defined before `boo()` is called.

```js
boo()

boo = function() {
  console.log('Yay!')
}
```

Edit:

I forgot to mention that it's foo.bar = function(), not just boo=function. Sorry about that.

Answer: 
You need to Change from **Function Expression** to a **function Declaration.**

The **hoisting** Rule work in case of Function declaration, but the function definition is not *Hoisted* in case of function Expression. 

In simple words, **Javascript runtime works in 2 passes**, in the first pass it will look for all the declaration and create a map of all the declaration. No code is executed. **In the next pass the code is evaluated** and if any unknown declaration is found it throws Reference error as it is not able to resolve that Reference.

In your case, In the first pass there isn't any declaration. So, No reference to the function is stored as it an function expression, where a variable is assigned the reference to a function which is evaluated in the next pass.

In the second pass, when code evaluation begins, boo variable has already been declared as a global variable and has `undefined` value. The statement `boo()` calls a function on variable which is `undefined`. So, you get the error. Hope it clears any confusion.

```js
boo();

function boo() {
  console.log('Yay!')
}
```
You have to declare it as a function, not a variable.

```js
boo();

function boo() {
  console.log('Yay!')
}
```