Jump to content

Don't use console.log like this


graduate
 Share

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"

Edited by graduate
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...