Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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
220,378 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.