Categories
ECMAScript Javascript

Constants

Const keyword is used to declare constant variables. Immutable is the one whose value cannot be modified. Const is the one whom we can assign value only once.

/**
 * to demonstrate the const variables, const variable are immutable
 */
const PRIMARY_VALUE = 100;
//PRIMARY_VALUE=200; second time assignment not allowed
console.log("PRIMARY_VALUE:::"+PRIMARY_VALUE);

const NUM_ARRAY = [1,2,3,4,5,6,7,8,9];
NUM_ARRAY.push(10);
//NUM_ARRAY = [11,12,13,14,15];//since array is const, reinitialization is not allowed. it will throw error
console.log("NUM_ARRY::"+NUM_ARRAY);

Output

Leave a comment

Design a site like this with WordPress.com
Get started