4

See the code below from lines 14-20 of this GitHub file. Why does Google use backticks or "template literals" in the require functions, instead of regular single or double quotes?

The code is from a testing script in Google's tutorial for using NodeJS on AppEngine. I researched template literals and the require function but could not find any resource explaining why one would use template literals in a require statement, or what effect it would have.

'use strict';

const testConfig = require(`./_test-config`);
const proxyquire = require(`proxyquire`).noPreserveCache();
const sinon = require(`sinon`);
const test = require(`ava`);
const utils = require(`@google-cloud/nodejs-repo-tools`);
Oliver Salzburg
  • 21,652
  • 20
  • 93
  • 138
nicholsonjf
  • 971
  • 2
  • 11
  • 21

2 Answers2

4

The relevant PR can be found here. PR does not indicate any particular reason why it's done that way which indicates that it's either the developer's taste or a show of ES features.

Google does have an updated JS code style document which covers newer syntax if you're curious how they'd like JS written.

Joseph
  • 117,725
  • 30
  • 181
  • 234
  • Interesting, thanks for pointing me to the pull request. I was able to find the person’s email address, so I asked him to check out my question and to answer if possible. If he doesn’t answer and if nobody else provides a plausible reason I’ll mark this answer correct tomorrow. – nicholsonjf Apr 11 '18 at 02:20
2

Yeah I'm going to be honest here - there was really no good reason. Template literals are great if youre doing string interpolation, but in this case it's likely unnecessary.

Justin Beckwith
  • 7,686
  • 1
  • 33
  • 55
  • That’s so weird because in the PR the person explicitly replaced the single quotes with template literals. Do you think they just misunderstood what TLs do or was there some purpose in mind? – nicholsonjf Apr 11 '18 at 18:46
  • I awarded this answer correct because Justin works for Google and has contributed to the GitHub repo I referenced in my question. Thus I'm assuming that of the two answers his comes closest to answering why they used the template literals. @Joseph's answer was very helpful and deserving of the upvotes it got. – nicholsonjf Apr 12 '18 at 01:02