I just wonder how variable hoisting in NodeJS works. In the example below
console.log(name);
var name = "Rambou";
execution returns undefined
which is correct since Hoisting works. var name;
is being moved to the top like
var name;
console.log(name);
name = 'Rambou';
The question is: Why hoisting does not work for let and const? Both examples below return exception of an undefined variable.
console.log(name);
let name = "Rambou";
console.log(name);
const name = "Rambou";
ReferenceError: name is not defined
at evalmachine.<anonymous>:1:13 at Script.runInContext (vm.js:133:20) at Object.runInContext (vm.js:311:6) at evaluate (/run_dir/repl.js:133:14) at ReadStream.<anonymous> (/run_dir/repl.js:116:5) at ReadStream.emit (events.js:198:13) at addChunk (_stream_readable.js:288:12) at readableAddChunk (_stream_readable.js:269:11) at ReadStream.Readable.push (_stream_readable.js:224:10) at lazyFs.read (internal/fs/streams.js:181:12)
Execution has happened at repl.it platform.