typeof 运算符
typeof toolResult
typeof 是一个运算符(不是函数,虽然大家常写成 typeof(x)),它返回一个字符串,取值只有 8 种:
表达式 结果
typeof 'abc' 'string'
typeof 123 'number'
typeof true 'boolean'
typeof undefined 'undefined'
typeof null 'object' ← 著名的历史遗留 bug
typeof {} / typeof [] 'object'
typeof function(){} 'function'
typeof Symbol() 'symbol'
typeof 10n 'bigint'
所以 typeof toolResult === 'string' 就是一个运行时类型判断:为真说明 toolResult 是字符串。

浙公网安备 33010602011771号