microvium
microvium copied to clipboard
var variable undefined
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();
My guess is that it's hoisted both var declarations separately rather than merging them.
What are you trying to achieve with this code?
I'm trying to avoid var, it is just that I've spotted a difference between official JavaScript and Microvium.
Ok, thanks for pointing it out. I've added it to the to-do list.