Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
export default new object

Is it guaranteed that export default new object(), where object is some kind of type (e.g. Date), returns the same object all the time?

// date.js
export default new Date()
// foo.js
import date from './date'
// bar.js
import date from './date'

Can it be expected that date in foo.js and date in bar.js are equivalent. So import date from './date' is a singleton?

Would the above export default new Date() be equivalent to module.exports = new Date() for pre-es6 era?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes, it will always be the same object. In any given run of a script, you can assume that the top level of a file, eg:

// date.js
export default new Date()

will run exactly once, and no more, if the file gets imported. Further imports of that file will result in date.js's exports being importable, but will not run date.js again.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!