Jump to content

Don't use console.log like this


graduate

Recommended Posts

I've spent some time solving this problem till I understood that `%` symbol has a special meaning in `console.log`, the same like in function `printf` in C programming language.

var str = '%apple', n = 25;console.log( str, n ); // You expect "apple 25" but you get "25pple"

Link to comment
Share on other sites

actually, I wouldn't be sure what to expect since you are using two variables delimited by a comma. perhaps the comma is open to interpretation. doing this achieves your expected result however.

var str = '%apple', n = 25;console.log(str + n); // outputs apple25

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...