js: Fix simple scopes example

Weirdly enough, the "simple-scopes" test doesn't return undefined
anymore, at first I thought the scoping was somehow broken, turns out
the interpreter doesn't consider the returned y as the last evaluated
value anymore, possibly because it's undefined (?).
This commit is contained in:
0xtechnobabble 2020-03-16 01:17:24 +02:00 committed by Andreas Kling
parent dfbaa8e543
commit 6780d70fb1
Notes: sideshowbarker 2024-07-19 08:16:41 +09:00

View File

@ -1,9 +1,11 @@
//I should return `undefined` because y is bound to the inner-most enclosing function, i.e the nested one (bar()), therefore, it's undefined in the scope of foo()
function foo() {
function bar() {
var y = 6;
}
bar()
bar();
return y;
}
foo(); //I should return `undefined` because y is bound to the inner-most enclosing function, i.e the nested one (bar()), therefore, it's undefined in the scope of foo()
print(foo());