Does a const stay constant?

A test to see if the browsers allows constants, defined with the 'const' keyword, to be updated.

by David Storey

HTML

<p>Open the Console in your browser. The value posted to the console should remain "Foo". If the second line changes the value to "bar", the browser supports the <code>const</code> keyword, but treats it like <code>var</code>.</p>

JavaScript

const CONSTANT_VARIABLE = "Foo";

/* should print "foo" to console */
printValue(CONSTANT_VARIABLE);

/* Try to change value. Should fail */
CONSTANT_VARIABLE = "Bar";

/* should still print "Foo" to console, not "Bar" */
printValue(CONSTANT_VARIABLE);

function printValue(val) {
    console.log("Value of CONSTANT_VARIABLE is " + val);
}