Bug (minor): Extraneous line in Example

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes

Example

const array = [50, 60, 70];
array[0];
const data = array[1];

array[0]; should not be there.

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

The line is part of the example and getting explained below.
You are right, it doesn’t serve any purpose in the actual code - but it is there for a reason and should not be removed.

It would be better if the example’s description says no space should be in between “array[1]”; thus, eliminating the need for “array[0];”.

[This is not assembly where instructions which appear to do nothing are actually used for timing purposes.]

The line where array[0] is used is directly below the code:
array[0] is now 50 , and data has the value 60 .
And it’s there to show what it means for the first element to have index 0. That’s why it cannot get eliminated in general.

I suggest

console.log(array[0]);

similar to https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop

1 Like

Better yet, just make it a comment so you don’t have to explain about console.log():

// array[0] is now 50

I’m not wild about commented out code. That is worse, in general.

1 Like

Or just leave it as is - array[0] is 50. That’s a fact. And the line in the code is not wrong. Useless for the code, but not wrong.

no comments in examples, for localization issues

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.