This blog is based off of http://www.hedgerwow.com/360/dhtml/js_constant.html.
- A constant is defined as:
- A variable whose value cannot change through assignment or be re-declared while the script is running
- A constant is declared using the
constkeyword. - The scope of a constant is the same as the scope would have been had it not been declared as a constant (local within a function, global outside of a function, or as a closure.
Thru a simple example, Hedger shows that Opera does not respect constants.
If you define a constant, you should not be able to change the value of the constant in your script.
function hello() {};
const hello = 'goodbye'; //should throw an error
function myfunction() {
const hello= 'goodbye';
var hello = 42; //should throw an error
//statements
}
Hedger defines his constants using the define method.
Advertisement