coder-mike / microvium

A compact, embeddable scripting engine for applications and microcontrollers for executing programs written in a subset of the JavaScript language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

var variable undefined

boogie opened this issue · comments

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.