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 trial


Kieran Barker
Kieran Barker
15,028 Points

My variable is shorter than Dave's, but is one better than the other?

I've just finished the 'Practice Basic Variables, Input & Output in JavaScript' workshop with Dave McFarland. His solution to step three of the challenge was as follows:

var completeName = firstName.toUpperCase() + ' ' + lastName.toUpperCase();

My solution was as follows:

var fullName = (firstName + ' ' + lastName).toUpperCase();

My question is: is one solution 'better' than the other? I feel like mine is more efficient, but could there be a scenario in which it might be better to use Dave's method?

Thank you in advance! :-)

1 Answer

Steven Parker
Steven Parker
229,920 Points

In this case both solutions are equivalent, though Dave's more strictly addresses the objective. It would only make a practical difference if something other than a space were being concatenated with the capitalized names that you did not also want to be capitalized.