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.

JavaScript AJAX Basics (retiring) AJAX and APIs Making the AJAX Request

What's the more common practice for passing data to $.getJSON: using variables or hard coding inline?

I know the video says both are common, but I'd love to know which is more common // or considered best practice. Are there performance improvements either way?

Seems like the latter would be easier to debug as there is less obfuscation. Are there other considerations?

Thanks! JS

1 Answer

I don't think there's an easy answer for this, since getting the numbers to determine the more common approach would be difficult/near impossible, and 'best practice' is always a subjective opinion shared by a number of people.

As far as the use of variables go, I think the rule of thumb is that if you need it more than once or it makes it clearer to read and understand the code, then use a variable.