Skip to content

Instantly share code, notes, and snippets.

@andrewmmc
Last active January 8, 2018 07:47
Show Gist options
  • Save andrewmmc/082734b10af7b78461fa32f27338d357 to your computer and use it in GitHub Desktop.
Save andrewmmc/082734b10af7b78461fa32f27338d357 to your computer and use it in GitHub Desktop.
[JavaScript ES6] Const / let

JavaScript ES6 - const / let

Note: Don’t confuse const with mutable objects. As I said, you cannot assign some other value to the const variables, but you can modify the const value. Constant Reference, Not Value:The other new keyword for variable declaration in ES6 is const, but it is often misinterpreted as being a “constant value”. Instead, in ES6 a const represents a constant reference to a value (the same is true in most languages, in fact). In other words, the pointer that the variable name is using cannot change in memory, but the thing the variable points to might change. For example,

‘use strict’;
const a = {};
a.a = 1;

is perfectly valid, because we are not changing what is assigned to a, but we are changing the object pointed by a.

Reference: https://medium.com/@pandeysoni/when-should-use-const-and-let-instead-of-var-in-javascript-ec2c3d7e5ca6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment