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

120
Views
Javascript: Understanding of generated Javascript function & associative arrays from Typescript

i am newbie to Typescript and i am confused from the generated Javascript below.

Original Typescript:

enum DaysOfTheWeek {
SUN, MON, TUE, WED, THU, FRI, SAT
};

let day: DaysOfTheWeek;
day=DaysOfTheWeek.MON;

if (day === DaysOfTheWeek.MON) {
    console.log("Got to go to work!");
}

Generated Javascript:

var DaysOfTheWeek;

(function(DaysOfTheWeek) {
  DaysOfTheWeek[DaysOfTheWeek["SUN"] = 0] = "SUN";
  DaysOfTheWeek[DaysOfTheWeek["MON"] = 1] = "MON";
  DaysOfTheWeek[DaysOfTheWeek["TUE"] = 2] = "TUE";
  DaysOfTheWeek[DaysOfTheWeek["WED"] = 3] = "WED";
  DaysOfTheWeek[DaysOfTheWeek["THU"] = 4] = "THU";
  DaysOfTheWeek[DaysOfTheWeek["FRI"] = 5] = "FRI";
  DaysOfTheWeek[DaysOfTheWeek["SAT"] = 6] = "SAT";
})(DaysOfTheWeek || (DaysOfTheWeek = {}));
;
var day;
day = DaysOfTheWeek.MON;
if (day === DaysOfTheWeek.MON) {
  console.log("Got to go to work!");
}

Questions:

  1. The var DaysOfTheWeek does not seems like it's an array. From what i understand an array needs an empty array instance like below:

    var ar = [];

  2. Arrays only uses index. Yet we have DaysOfTheWeek[DaysOfTheWeek["SUN"] = 0] = "SUN"; Seems like associative arrays? Can someone slowly explain in steps?

    DaysOfTheWeek[DaysOfTheWeek["SUN"] = 0] = "SUN"; -- breaking it down below
    1. DaysOfTheWeek["SUN"] = 0 -- seems like assigning key "SUN" with value 0?
    2. DaysOfTheWeek[DaysOfTheWeek["SUN"] = 0] = "SUN" -- this part confuses me!!
    
  3. On function (DaysOfTheWeek) itself, i am confused stmt B construct at the bottom of this function. What is this?

Appreciate any help.

about 4 years ago · Juan Pablo Isaza
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!