Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialhoracinis
4,824 PointsIn the console.log(prop, ": ", person[prop]);
I am just a little confused as to why you used commas instead of the "+" to print this in the console. Would there be any difference if "+" was used instead of the commas?
Thank you
1 Answer
Jeff Muday
Treehouse Moderator 28,720 PointsThe majority of the time I use console.log, I am logging string values during debugging scripts, so then it is only a cosmetic difference when you use comma syntax over plus expression. The difference is the that the commas impose a space character between items. (See below "Henry David Thoreau example).
The reason one might choose a comma syntax is to keep the discreet (unchanged) values in the log when combining similar data types. Note three integers x, y, and z, are computed when you use a plus because of the datatype coersion, and when they are logged with commas, we can still see their original values.
> var first="Henry";
> var middle="David";
> var last="Thoreau";
> console.log(first+middle+last);
HenryDavidThoreau
> console.log(first,middle,last);
Henry David Thoreau
> var x = 0;
> var y = 1;
> var z = 2;
> console.log(x + y + z);
3
> console.log(x,y,z);
0 1 2
horacinis
4,824 Pointshoracinis
4,824 PointsNice! Thank you for the great explanation!