ES6: Mutate an Array Declared with const

ES6: Mutate an Array Declared with const
0
#1

Hi,

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!

#2

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
#3

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:

#4

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
#5

Now it is clear to me. :slight_smile:

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

#6

I’m glad I could help. Happy coding!

1 Like