The output will be `undefined`. This demonstrates how hoisting works with `var` declarations. During the compilation phase, the declaration `var x;` is hoisted to the top of its scope, but the initialization `x = 5;` remains in its original position. So, the code effectively runs as if it were written:
```javascript
var x; // x is declared but not initialized, so its value is undefined
console.log(x); // logs undefined
x = 5; // x is assigned the value 5
```
This behavior is specific to variables declared with `var`. It's one of the reasons why modern JavaScript often prefers `let` and `const` declarations, which are hoisted but remain in a 'temporal dead zone' until their actual declaration line, causing a ReferenceError if accessed before declaration rather than returning `undefined`.