var variable undefined
boogie opened this issue · comments
Andras Barthazi commented
It seems there is an issue related to var
declarations:
function main() {
var x = 'before';
console.log(x);
var x = 'after';
}
main();
The expected behaviour is printing "before", while it prints "undefined".
This code work as expected:
function main() {
x = 'before';
console.log(x);
var x = 'after';
}
main();
Michael Hunter commented
My guess is that it's hoisted both var declarations separately rather than merging them.
What are you trying to achieve with this code?
Andras Barthazi commented
I'm trying to avoid var, it is just that I've spotted a difference between official JavaScript and Microvium.
Michael Hunter commented
Ok, thanks for pointing it out. I've added it to the to-do list.