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 Node.js Basics (2014) Building a Command Line Application Handling Parsing and Status Code Errors

Floyd Orr
Floyd Orr
11,723 Points

Is this production code from node document or just example. I see there is no function is this a different style .

I was just wondering if this is production code or just example of node and I should fill in blanks by writing a function and missing parts? "(res)=>" and ${})??? Is this literal ? http.get('http://www.google.com/index.html', (res) => { console.log(Got response: ${res.statusCode}); // consume response body res.resume(); }).on('error', (e) => { console.log(Got error: ${e.message}); });

2 Answers

Nicholas Grenwalt
Nicholas Grenwalt
46,626 Points

That code is using EcmaScript2015 (the newest version of JavaScript). The "(res)=>" is an arrow function which basically is a shorthand way to write functions now. That would be the same as writing "function (res)" in older versions of JS. And the ${} is how you do interpolation. This allows you to dynamically pass in values. Hope that helps! If you want to up your knowledge more on ES2015 here is a great resource: https://babeljs.io/docs/learn-es2015/

Floyd Orr
Floyd Orr
11,723 Points

Thank you. That had me scratching my head I'm glad I asked instead of assuming the wrong thing.