Kevin Meredith Kevin Meredith - 3 years ago 146
Javascript Question

JavaScript const Keyword

Does the

keyword in JavaScript create an immutable reference to immutable data structures? [I'm assuming that immutable data structures exist in JavaScript.]

it appears to do so:

var x = "asdf";
const constantX = x;

alert("before mutation: " + constantX);
x = "mutated"
alert("after mutation: " + constantX);


before mutation: asdf

after mutation: asdf

Answer Source

Yes, it does, but it is not been standardized and is not supported in all browsers.

See this MDN article on the const keyword for details and compatability.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download