// main.js —— typeof 全表 // 结论只用可运行的值来支撑:每一行都是 typeof 的真实返回。 class SampleClass {} function sampleFn() {} const generatorObject = (function* () {})(); export const SAMPLES = [ ['undefined', undefined], ['null', null], ['true', true], ['42', 42], ['1n', 1n], ["'x'", 'x'], ['Symbol()', Symbol('s')], ['{}', {}], ['[]', []], ['function () {}', sampleFn], ['class SampleClass {}', SampleClass], ['/re/', /re/], ['new Date()', new Date()], ['Promise.resolve()', Promise.resolve()], ['[].values()(迭代器对象)', [].values()], ['(function*(){})()(生成器对象)', generatorObject], ['new Map()', new Map()], ['new Number(1)(装箱)', new Number(1)], ]; export function typeofTable() { return SAMPLES.map(([label, value]) => ({ label, type: typeof value })); } export function run(log = console.log) { const rows = typeofTable(); log('表达式 => typeof'); for (const row of rows) log(`${row.label} => ${row.type}`); log('-'.repeat(46)); log("注意:typeof null === 'object',而 typeof [] === 'object',两者完全不同的东西。"); return rows; }