代码输出什么?为什么
console.log(typeof typeof typeof null);
代码输出结果为 string。这是因为 typeof null 的值为 object,typeof "object" 的值为 string,typeof "string" 的值也为 string,因此连续使用三个 typeof 操作符,最终得到的结果是 string。需要注意的是,typeof null 的值为 object,这是 JavaScript 语言本身的一个历史遗留问题,因为在 JavaScript 的早期版本中,null 被错误地认为是一个对象。
console.log(typeof console.log(1));
代码输出结果为 undefined。这是因为 console.log() 函数本身没有返回值,因此它的返回值是 undefined。在这个代码中,先执行 console.log(1) 函数,它会将数字 1 输出到控制台,并返回 undefined,然后再执行 typeof undefined 操作符,最终得到的结果是 undefined。