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

Gabriel Edward Gabato
Gabriel Edward Gabato
4,651 Points

Why do I get a 404 if I type with ('') but not (``)?

I thought that they are equal. For example:

'https://teamtreehouse.com/${username}.json' gets me a 404

but

https://teamtreehouse.com/${username}.json gives me a 200

Thanks in advance!

2 Answers

Andrew Thompson
Andrew Thompson
28,063 Points

Hi Edward,

The reason this is happening is that backticks are the new syntax for creating Template Strings in ES2015. Single quote marks and double quote marks are indeed equal but using backticks will allow you to use string substitution. Substitution allows us to take any valid JavaScript expression and inside a Template Literal, the result will be output as part of the same string. I have included two examples below of the same code, one written in ES5 and the other in ES2016 to demonstrate this

ES5

var username = 'user';

var req = https.get('https://teamtreehouse.com/' + username + '.json';

ES2015

const username = 'user';

const req = https.get(`https://teamtreehouse.com/${username}.json`;

how can I make this sign with keyboard? I do not find anything on web.

Andrew Thompson
Andrew Thompson
28,063 Points

Hi Irene,

Not sure if you have worked this out yet... If you're on a Mac, it will be between the shift key and the Z key (UK keyboard). If you are on a US keyboard, I think it is below the ESC key.

It shares a key with the tilde character.

Hope this helps.