What characters are valid for JavaScript variable names?

JavascriptWeb DevelopmentFront End Technology

To check the valid characters for JavaScript variable names, you should follow the below given naming conventions, which discuss about other rules to name a variable −

  • Name can begin with $ and _ characters, for example, _result.
  • You should not use any of the JavaScript reserved keywords as a variable name. These keywords are mentioned in the next section. For example, break or boolean variable names are not valid.
  • JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or an underscore character. For example, 123test is an invalid variable name but _123test is a valid one.
  • JavaScript variable names are case-sensitive. For example, Name and name are two different variables.

Here are the correct forms of a variable name in JavaScrip −

result
 _result

The following is an incorrect form for a variable name −

2result
raja
Published on 25-Jan-2018 10:59:10
Advertisements