I cannot see why this coding is needed here

I cannot see why this coding is needed here
0

#1

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.


#2

Hi,

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.


#4

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


#5

const character;

You can’t do that.

Description
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

#6

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