I cannot see why this coding is needed here

Hi people, My name is Shuto. This is my first question here.

So far, I’ve been through a basic lecture of JavaScript, using Progate app. In this section, which emphasizes arrays and iteration, I got a task to make a list of three people’s name and age using [for] loop. Then, as I go through it, I thought I succeeded to put correct coding (actually exact the same letters are reflected on the consoles). BUT, here, the app says some coding, which is to define another variable element, are needed where the comment is set.

I have no idea {1}how I define the constant and {2}why it is needed, even if things on the console are the same.

Thank you.


Here you assign the characters[i] value to the character constant so that it is easier to read and maintain code. So instead of characters[i].name it becomes character.name.

1 Like

Thank you for answering! Now, I can see that I should make another constant, in order to make code more easier to read.

const character;

You can’t do that.

An initializer for a constant is required; that is, you must specify its value in the same statement in which it’s declared (which makes sense, given that it can’t be changed later).

const character;
Uncaught SyntaxError: Missing initializer in const declaration

Duhh, yeah my answer is wrong, i think i should remove it