Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda