Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/js-interpreter.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940test("basic functionality", () => { let callHoisted = hoisted(); function hoisted() { return "foo"; } expect(hoisted()).toBe("foo"); expect(callHoisted).toBe("foo");});
// First two calls produce a ReferenceError, but the declarations should be hoistedtest("functions are hoisted across non-lexical scopes", () => { expect(scopedHoisted).toBeUndefined(); expect(callScopedHoisted).toBeUndefined(); { var callScopedHoisted = scopedHoisted(); function scopedHoisted() { return "foo"; } expect(scopedHoisted()).toBe("foo"); expect(callScopedHoisted).toBe("foo"); } expect(scopedHoisted()).toBe("foo"); expect(callScopedHoisted).toBe("foo");});
test("functions are not hoisted across lexical scopes", () => { const test = () => { var iife = (function () { return declaredLater(); })(); function declaredLater() { return "yay"; } return iife; };
expect(() => declaredLater).toThrow(ReferenceError); expect(test()).toBe("yay");});