I just can't understand, before last if - log outputs int value, after if - same log shows error:
"Cannot access 'nextImgId' before initialization" whats up with that? The caraible is declaired before it is used, so it can be because of temporal dead zone.
let nextImgId = img.getAttribute('data-next-id');
if (nextImgId !== null) {
nextImgId = parseInt(nextImgId);
log(nextImgId);
if (true) {
log(nextImgId);
}
}
function log(...args) {
console.log(...args)
};
<img id=img src=//placekitten.com/50/50 data-next-id="123" />
I have tried refreshing the page expecting for reality to make sense, but it didn't happen :(
I know that this code is working and I can't just upload my project, where it doesn't work. The question could be what might cause a variable to disappear... Not what ir wrong with this code.
SOLVED: My mistake was to not include the rest of the code inside the if, where the problem was, that the variable was redeclared and that made the scope of that variable change.