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

JavaScript AJAX Basics (retiring) AJAX and APIs Make a JSONP request

Eric Brennan
Eric Brennan
14,490 Points

Can I use const and let instead of var with AJAX?

I went through the ES2015 js course here on treehouse teaching the const and let variables and how they're much better than var. Then I move on to the AJAX course and when I attempt to use these variables in the code challenges, I get syntax errors, and messages that say "it's always best to use var". I'm really confused because the previous courses said the complete opposite. Is it just a matter of updating the js syntax in the challenges with ES2015? I notice that the function shorthand () => {} doesn't work either. Or is this preference of "var" specific to JSON or AJAX?

1 Answer

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,684 Points

My guess is the AJAX course is pre-ES2015. The challenges are very specific to what content is provided, so I'd just stick to using var to pass. However, using const, let, and arrow functions can be used in "the real world".

To add to Rich's answer, ES6 requires a compiler such as Babel so unless it's explicitly set up in the real world to take ES6 or in Treehouse expect to have to use var and normal functions.

You can test out ES6 here: https://babeljs.io/repl/

Eric Brennan
Eric Brennan
14,490 Points

Thanks Rich & Bryan. Makes perfect sense