I read on one site that you can make constant variables in JavaScript like:
const x = 20;
but on another site I read that you can’t. So I am confused now what is it now?
Also in Visual Studio 2010 when I write const it underlines it in the JavaScript file and shows syntax error.
constis a proposed feature of ECMAScript Harmony (together with a properly block-scopedletit is supposed to replacevarand implicit globals). ECMAScript Harmony is a grab-bag of ideas for the next versions of ECMAScript.constwas also a part of ECMAScript 4.ECMAScript 4 was never released and never will be, and ECMAScript Harmony will only be released in a couple of years. Therefore, you cannot reliably use it.
There are some implementations or derivatives of ECMAScript that implement
const(ActionScript, for example). There are also some implementations that acceptconstas a synonym forvar(IOW, you can useconst, but it won’t give you any protection.)However, unless you absolutely can guarantee that your code will only run on very specific versions of very specific implementations of very specific derivatives of ECMAScript, it’s probably better to avoid it. (Which is a real shame, because
constand especiallyletare a huge improvement overvarand implicit globals.)