functional-programming-jargon icon indicating copy to clipboard operation
functional-programming-jargon copied to clipboard

Inaccuracy in the "Constants" section

Open Retsam opened this issue 7 years ago • 3 comments

From the section on constants:

With the above two constants the following expression will always return true.

john.age + five === ({name: 'John', age: 30}).age + (5)

This above statement isn't true; while john is declared as a constant; that only means that john can't be replaced with a different object, not that its fields can't be modified. A simple john.age = 10 would cause the above expression to return false, despite the definition of john as a constant.

Retsam avatar Jul 23 '16 18:07 Retsam

Yeah there's definitely common confusion about const not making objects immutable. This section should probably distinguish between them

jethrolarson avatar Jul 23 '16 19:07 jethrolarson

Yeah just came here to say that - a more straightforward example could just be to have const five and const six for instance.

joe-strummer avatar Jul 25 '16 13:07 joe-strummer

I think it could be fixed by saying it's referentially transparent for non-symbol primitives, the result of calling Symbol.for("global-symbol"), and the result of calling any pure function that only returns one of these.

dead-claudia avatar Aug 11 '16 21:08 dead-claudia