Created
March 7, 2015 20:46
-
-
Save mrspeaker/e9a68d4c96abdbe7f2bb to your computer and use it in GitHub Desktop.
Immutable parameters in ES6?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Is there a way to define immutable parameters in ES6? | |
const inc = x => { | |
x++; // Oh no, you modified x! | |
return x; | |
} | |
// Is it better to reassign to const (if it should be constant, of course)? | |
const inc = x => { | |
const x = x; | |
x++; // Booop... x is readonly! | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment