Which Characters Are Allowed in JavaScript Variable Names?

In JavaScript, a variable name:

  • Can begin with a letter, underscore (_) or dollar sign ($);
  • Can only contain letters, numbers, underscores, or dollar signs;
  • Cannot be the same as a JavaScript reserved word;
  • Cannot contain spaces;
  • Is case-sensitive.

For example, the following are all valid variable names:

const foo = 'bar';
const $foo = 'bar';
const _foo = 'bar';
const _123foo = 'bar';
const foo_bar123$ = 'bar';
const fooBar = 'bar';

Hope you found this post useful. It was published . Please show your love and support by sharing this post.