The output will be `'Hello!'`. This example demonstrates function hoisting. Even though the function `bar()` is defined after the `return` statement, function declarations are hoisted in their entirety to the top of their containing scope. As a result, the code effectively runs as if it were written:
```javascript
function foo() {
function bar() { // function declaration is hoisted
return 'Hello!';
}
return bar(); // bar is already defined and can be called
}
```
This is why the function `bar()` can be called successfully before its definition in the source code. Note that this behavior only applies to function declarations (using the `function name() {}` syntax). Function expressions (like `var bar = function() {}`) would follow variable hoisting rules where only the variable declaration is hoisted but not the function assignment. This feature of JavaScript allows for more flexible code organization where helper functions can be defined after they're used.