typeof-basic.js 642 B

123456789101112131415161718192021222324252627
  1. load("test-common.js");
  2. try {
  3. assert(typeof "foo" === "string");
  4. assert(!(typeof "foo" !== "string"));
  5. assert(typeof (1 + 2) === "number");
  6. assert(typeof {} === "object");
  7. assert(typeof null === "object");
  8. assert(typeof undefined === "undefined");
  9. var iExist = 1;
  10. assert(typeof iExist === "number");
  11. assert(typeof iDontExist === "undefined");
  12. var calls = 0;
  13. Object.defineProperty(globalThis, "foo", {
  14. get() {
  15. calls++;
  16. },
  17. });
  18. assert(typeof foo === "undefined");
  19. assert(calls === 1);
  20. console.log("PASS");
  21. } catch (e) {
  22. console.log("FAIL: " + e);
  23. }