graduate Posted January 26, 2012 Share Posted January 26, 2012 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 More sharing options...
thescientist Posted January 26, 2012 Share Posted January 26, 2012 I don't see the %. Link to comment Share on other sites More sharing options...
graduate Posted January 26, 2012 Author Share Posted January 26, 2012 Sorry, I changed my first post. Link to comment Share on other sites More sharing options...
thescientist Posted January 26, 2012 Share Posted January 26, 2012 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 More sharing options...
graduate Posted January 26, 2012 Author Share Posted January 26, 2012 Yes, when you dont use the %, the function just join its arguments into a string, with % it uses the first argument as a pattern and includes into it the others. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.