Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda