Why does console.log (true, '\ t') print true?

In Chrome, the following

console.log(true, '\t');

will print

true "  "

Why do quotation marks exist?

(Note that it console.log(true + '', '\t')will print only true, just as it console.log('a', '\t');will print only a.)

+5
source share
2 answers

There are basically two overloads for console.log:

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

More specifically, for the source code , if the first parameter is a string, then it treats it as a format string for other parameters. Otherwise, each parameter is output directly.

, console.log(true + '', '\t') "true", , \t -, console.log(true, '\t') , true .

+11

console.log(true, '\t');
true "  "

console.log(false, '\t');
false " " 

, , false , true o_O... , \t

console.log('\t', true);
     true

, , , , , .

console.log(false, '\t', '\t');
false " " " "

, , , , , . , Google Chrome? , .

+2

All Articles