How you can declare string constants in JavaScript

Hi guys, today I want to explain to you how you can declare string constants in JavaScript. I will show you two ways to declare string constants.

The first way is:

var constants = {
'constant1': 'first constant',
'constant2': 'second constant'
};

To call this constants, you must use:

constants.constant1

alert(constants.constant1);

The second way:

var constant = 0;

function call()
{
constant = 10
}

call();

alert(constant);

You can see the results in this video:









Leave a Comment