ES6 - Why declare inline function as const?

Is it a just a standard to declare an inline function as const or there is a advantage that I am missing?

Can ‘let’ be used?

PS: it would be nice to talk about what are anonymous /inline functions in the basic JS section instead of dropping in the middle of ES6. it is so confusing.

Challenge: Use Arrow Functions to Write Concise Anonymous Functions

Link to the challenge:

You can use let in theory… but you should always use const for any variable you declare unless you plan on changing the contents of the variable, in which case you should use let instead. You don’t want to overwrite what your function does - so we use const instead of let.

1 Like

Thank you.
I think I will get a better understanding as I progress in JavaScript.
But in practice and in general, I should use const to declare variables / functions to avoid side effects and changes to variables / code.

const prevents accidentally changing something you did t mean to be changed. Side effects refers to something else.

1 Like

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