为什么console.log(true,'\ t')打印为true""?

Ran*_*lue 5 javascript google-chrome

在Chrome中,以下内容

console.log(true, '\t');
Run Code Online (Sandbox Code Playgroud)

将打印

true "  "
Run Code Online (Sandbox Code Playgroud)

为什么有引号?

(请注意,console.log(true + '', '\t')只会打印true,console.log('a', '\t');只会打印a.)

Ste*_*ell 11

基本上console.log有两个重载:

console.log(formatString, args)console.log(arg1, arg2, ...).

更具体地说,根据源代码,如果第一个参数是字符串,则它将其视为其他参数的格式字符串.否则,直接输出每个参数.

因此console.log(true + '', '\t')输出'true',因为第一个参数是一个字符串,并且没有占位符\t,并且console.log(true, '\t')将输出两个参数,因为true它不是字符串.