typeof.js 1.44 KB
Newer Older
1
// Copyright 2008 the V8 project authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

'use strict';
6

7
// The type of a regular expression should be 'object', including in
8
// the context of string equality comparisons.
9 10
{
  const r = new RegExp;
11

12 13 14
  assertEquals('object', typeof r);
  assertTrue(typeof r == 'object');
  assertFalse(typeof r == 'function');
15

16 17 18
  function equals(x, y) { return x == y; }
  assertTrue(equals('object', typeof r));
}
19 20

assertFalse(typeof null == "undefined");
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

assertEquals('undefined', typeof undefined);
assertEquals('object', typeof null);
assertEquals('boolean', typeof true);
assertEquals('boolean', typeof false);
assertEquals('number', typeof 42.42);
assertEquals('number', typeof 42);
assertEquals('bigint', typeof 42n);
assertEquals('string', typeof '42');
assertEquals('symbol', typeof Symbol(42));
assertEquals('object', typeof {});
assertEquals('object', typeof []);
assertEquals('object', typeof new Proxy({}, {}));
assertEquals('object', typeof new Proxy([], {}));
assertEquals('function', typeof (_ => 42));
assertEquals('function', typeof function() {});
assertEquals('function', typeof function*() {});
assertEquals('function', typeof async function() {});
assertEquals('function', typeof async function*() {});
assertEquals('function', typeof new Proxy(_ => 42, {}));
assertEquals('function', typeof class {});
assertEquals('function', typeof Object);