The const
declaration is (sort-of) hoisted, so it's as if your code looked like this:
const baz; // hoisted, sort-of
class Foo {
constructor() {
console.log('Foo baz is:', baz)
}
}
function log() {
console.log('log baz is:', baz);
}
baz = '123123'; // not really possible because it's const
log();
new Foo();
So there's a dead zone, but nothing actually happens in the dead zone; you don't make the function calls until after the dead zone so it's all good. It's fine to mention a symbol in its dead zone in nested function contexts. The dead zone is all about actively "touching" a hoisted symbol before its actual point of declaration.
Actually, because of the "temporal dead zone" concept, it's not really meaningful to think of const
and let
declarations as being "hoisted" the way var
declarations are. This particular example is a good illustration of how the declarations can seem to be hoisted however, as the references in the nested lexical contexts do actually work because the symbol is defined by the time the code in those functions actually runs.