Take the 2-minute tour ×

I searched if JavaScript offers a mean to define symbolic constants, but didn't find anything. Did I miss something ?

Is it a common practices to use const var instead ?

var const MAXIMUM_VALUE = 100;


share|improve this question

2 Answers 2

up vote 5 down vote accepted

const is not supported by IE, so if you want to support IE that is out of the question.

As far as I know, and the best way of doing this to keep it simple is to just have a naming convention for your constants like the ever-popular ALL UPPERCASE. There are some examples out there to force constants but they are not worth it for the most part. Alternatively, you could use a function:

function myConst() { return 'myValue'; }

This can of course still be overridden but I've seen it used.

Also see:

share|improve this answer
you can still replace the myConst function. later in the code: myConst = function() { return 'newValue'; } –  Joel Coehoorn Mar 26 '09 at 16:46
I thought const worked in IE now, but not in Opera. Is this wrong? –  Kevin Crowell Mar 26 '09 at 16:47
I know, but it'd take a deliberate amount of effort. –  Paolo Bergantino Mar 26 '09 at 16:48
Kevin: as far as I know it doesn't work in IE. I'll go check, though... –  Paolo Bergantino Mar 26 '09 at 16:52
I couldn't find the other similar questions - even with google. –  philant Mar 26 '09 at 20:32

Yes. But you remove the var. const replaces var.

const MAXIMUM_VALUE = 100;
share|improve this answer

Your Answer


