function-hoisting.js 845 B

12345678910111213141516171819202122232425262728293031323334353637
  1. load("test-common.js");
  2. try {
  3. var callHoisted = hoisted();
  4. function hoisted() {
  5. return true;
  6. }
  7. assert(hoisted() === true);
  8. assert(callHoisted === true);
  9. {
  10. var callScopedHoisted = scopedHoisted();
  11. function scopedHoisted() {
  12. return "foo";
  13. }
  14. assert(scopedHoisted() === "foo");
  15. assert(callScopedHoisted === "foo");
  16. }
  17. assert(scopedHoisted() === "foo");
  18. assert(callScopedHoisted === "foo");
  19. const test = () => {
  20. var iife = (function () {
  21. return declaredLater();
  22. })();
  23. function declaredLater() {
  24. return "yay";
  25. }
  26. return iife;
  27. };
  28. assert(typeof declaredLater === "undefined");
  29. assert(test() === "yay");
  30. console.log("PASS");
  31. } catch (e) {
  32. console.log("FAIL: " + e);
  33. }