JavaScript Node.js Basics Building a Command Line Application Making a GET Request with https

Leo Marco Corpuz
Leo Marco Corpuz
18,975 Points

Response function

I see in the video that the response function has no () before the arrow. Is the () optional?

1 Answer

Mischa Yartsev
Mischa Yartsev
15,552 Points

Hi, Leo Marco Corpuz !

Yes, you're right. If your Arrow function has only one argument like in this case only one argument response than you could omit the brackets.

const request = https.get(`https://teamtreehouse.com/${username}.json`, response => {
  console.log(response.statusCode)
})

Please refer to MDN docs:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

or of course Treehouse workshop for more info about Arrow functions:

https://teamtreehouse.com/library/introducing-arrow-function-syntax