Created
September 10, 2017 03:36
-
-
Save StevenJL/47127144a14100528b4e9fb5f2ae5bbf to your computer and use it in GitHub Desktop.
const
This file contains hidden or 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
// cannot re-assign a const variable | |
const x = "written in stone"; | |
x = "changed my mind"; // raises TypeError: Assignment to constant variable | |
// but you can still mutate a const variable | |
const person = {}; | |
person.name = "Steve"; | |
/* | |
`const` is great for assigning to a module that is required into code, | |
so as to prevent the variable holding the module from being accidentally reassigned: | |
*/ | |
// note 'require' is provided by node.js | |
const important_library = require("important_library"); | |
important_library = "I totally forgot this was const"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment