Example given in FCC article does not work

let newArray = [a, b, c, d, e];

let [firstLetter, , , ,lastLetter] = [a, b, c, d, e];

In JavaScript Concepts to Know Before Learning React

Hi there and welcome to the forum!

I slightly amended your topic to make your query a little clearer.
This example, given in the linked article, is illustrative but you’re right.
It doesn’t work as is, because the array elements should be in quotes if they are not predefined variables.

So, if you try the example but enclose all of the letters within quotation marks, the example will work and demonstrate the principle being described.

Hi Doug: Thanks for your reply. I agree the code can be corrected and you illustrated how. However, my main motive was to show that a tutorial had been posted, apparently without testing. I was astonished, but this is my first time here. Are postings checked? Are errors corrected? Should I expect this to be a normal occurance? Thanks.

Well, technically other examples in the same article don’t work either if you simply copy/paste them into a code editor as is (e.g. the if ... else statement).

Still, it’s common practice to give examples like this for illustrative purposes.
They are technically sound, in the sense that they would work if the variables used were predefined elsewhere.

Unless you’re working with an interactive tutorial, you wouldn’t usually expect examples to be tailored in such a way that they work out-of-the-box like that.

The FCC Javascript Algorithms and Data Structures course covers all of these concepts (and far more) interactively.

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