July 2018
Intermediate to advanced
420 pages
8h 46m
English
enum allows us to group values with more intuitive names. Some people prefer to call the enumerated list and some other names. Let's look at an example, so as to make it easier to understand how this works in practice:
enum bands { Motorhead, Metallica, Slayer}console.log(bands);tsc enum.ts
node enum.js
You will see the following result in the Terminal:
{ '0': 'Motorhead', '1': 'Metallica', '2': 'Slayer', Motorhead: 0, Metallica: 1, Slayer: 2 }
We can now get the value by using the name instead of the position.
Read now
Unlock full access