You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log = vmImport(1);
function sayHello() {
var arr = [1, 2, 3];
for (var i = 0; i < 3; ++i) {
console.log(arr[i]);
}
for (var i = 0; i < 3; ++i) {
console.log(arr[i]);
}
}
vmExport(1234, sayHello);
causes mvm_call() error with a return value of 12 when entering sayHello(), on tag 0.0.25.
My Javascript expertise is limited, but after some poking around I think it's the second var i = 0 in the second for loop that chokes Microvium. If I just change the second var i = 0 into i = 0, it works fine.
The text was updated successfully, but these errors were encountered:
Jerryxia32
changed the title
mvm_call() error on multiple declarations for same variable across for loops
mvm_call() error on multiple declarations of same variable across for loops
Nov 22, 2022
In the meantime, can I suggest using let instead of var. In JS, var declarations are hoisted to the function level, so two var declarations with the same name in the same function are actually the same function-level var declaration, which can lead to subtle bugs in your code. Here's some more detail about the differences on Stack Overflow.
This reduced test case
causes
mvm_call()
error with a return value of 12 when enteringsayHello()
, on tag 0.0.25.My Javascript expertise is limited, but after some poking around I think it's the second
var i = 0
in the second for loop that chokes Microvium. If I just change the secondvar i = 0
intoi = 0
, it works fine.The text was updated successfully, but these errors were encountered: