const scope code example

Example 1: const in javascript

const value = 10;
const constant = value;

Example 2: js define constant by element id

const elem = document.getElementById('elementID');

Example 3: const { message }

const { bar } = foo; // where foo = { bar:5, baz:2, bat: 10 };
/* This creates a constant with the name 'bar', which has a value of 5 */
const { message } = new assert.AssertionError({
  actual: 1,
  expected: 2,
  operator: 'strictEqual'
});

Example 4: const js +=

const foo; // Errror as const cannot be kept un-initialized;
const foo = "foo";
console.log(foo); //Output: foo
foo += " bar"; //Error

Tags:

Misc Example