Suggestion for ES6 introduction to const

Suggestion for ES6 introduction to const
0

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword

I want to suggest changing some text and the test for this lesson.

Also, rename variables declared with const to conform to common practices, meaning constants should be in all caps.

I understand noting this, but not sure that it should be a hard-and-fast rule enforced by the test. Consider something like:

const MyComponent = (props) => (<div {...props} />);

or even

const findEntryByName = (name) => ({firstName}) => (firstName === name);
...
const entry = someArray.find(findEntryByName('Daisy'));
if (entry) {
    // do things
}

In these examples, the variables are meant to be read-only, but don’t need to be CONSTANTCASED. In this lesson const sentence = ... should be okay.

Thanks for listening!

I would even go so far as to call this complete balderdash. Use const for everything unless you have a specific reason to re-bind the variable and thus use let. Then just name your variables normally. Exported module-level constants should probably follow that ALL_CAPS naming convention, but that has to do with it being global, not const.

1 Like