<html>
<head><title>Using the const Keyword</title>
<script type="text/javascript">
const NOON = 12;
const FREEZING = 32; // Can't change
</script>
</head>
<body bgcolor="silver">
<big>
<script type="text/javascript">
document.write("Fahrenheit temp is " + FREEZING + ".<br />");
FREEZING =32 + 10;
NOON = NOON + " noon";
document.write("Make it warmer " + FREEZING + ".<br />");
document.write("See you at ", NOON, ".<br />");
</script>
</big>
</body>
</html>
Above code is working fine with Firefox, Chrome, Safari but it is not working with opera 12.02. Since I have used keyword ‘const’ Result should be as follow
Farenheit temp is 32.
Make it warmer 32.
See you at 12.
But opera browser displays
Farenheit temp is 32.
Make it warmer 42.
See you at 12 noon.
What is wrong here.
What’s wrong is that
constisn’t officially supported in Opera, that’s all. It’s been a long time that developer claimed that, but it still lags behind. It’s still not part of ECMASCript.Try this instead:
This works in Opera. If you intend to support IE<9 too, you should use something a bit different (and less effective):
You still won’t be able to change its value, but you’ll be able to redefine
NOONwithObject.defineProperty.