ES6: Mutate an Array Declared with const


I just wanted to report that in this challenge the “s” is in small cap, even if it is a constant, so when someone tryes to solve it with all caps, the challenge throws an error.

Thank you for the attention and for all your amazing work!

This is something that comes up from time to time, especially for campers with experience in other programming languages.

const is a type of variable declaration, but it’s not exactly the same as what we consider “constants”. For one thing, it’s mutable (as this challenge is intended to show). More simply, const is a constant reference, not constant value. In JavaScript, as other languages, it is conventional to name conventional constants in all caps, regardless of the declaration type.

const PI = 3.14159;
const pieTypes = ['blueberry', 'apple'];
pieTypes.push('key lime'); // perfectly acceptable
1 Like

Hi, thank you very much for the answer!

Actually I am learning only js, I don’t have experience in other languages (unfortunately), so my doubts are probably due to ignorance more than anything else. :stuck_out_tongue:

I get what you’re saying (about the difference between costant values and references), but my doubt comes from the previous challenge (ES6: Declare a Read-Only Variable with the const Keyword) in which it is said: “rename variables declared with const to conform to common practices, meaning constants should be in all caps”.

So, if I got what you’re saying, it’s perfectly fine to use both small and all caps to write constant names, is it right? :slight_smile:

It sounds like that other challange should be slightly reworded.

The const type doesn’t require any naming conventions. We just use all caps for specific kinds of values to communicate that they are read-only.

1 Like

Now it is clear to me. :slight_smile:

I really appreciated your help and your time, thank you very much! :slight_smile:

I’m glad I could help. Happy coding!

1 Like