0

I like to think I know JavaScript okay, but I've recently seen something interesting in one of the codebases I had access to (for a very limited time). I saw a JavaScript object with a name that looked similar to this:

Variable$Name$Example$Here = ...

In fact, I'm not even sure if that's a variable per-se, or a different type of JavaScript object (i.e. a primitive or not). Now I know that $ is usually used to denote an instance of a jQuery, but I haven't seen it in the middle of the object name.

Did they simply name it that way? Is there simply somewhere e.g.

var Variable$Name$Example$Here = true;

... or am I completely missing something here?

Bo Milanovich
  • 7,995
  • 9
  • 44
  • 61
  • 3
    `$` is a valid variable name character just as any letter is. Looks like the developer is using something other than CamelCase or underscores to make it readable. – j08691 Jun 16 '14 at 16:35
  • ...as well as underscore. – Andy Jun 16 '14 at 16:36
  • 1
    I've never seen the `$` used in the middle of variables, but some developers like to prepend it to variable names to represent that it holds a jQuery reference. (i.e. `var $divs = $('div');`) – Ryan Erdmann Jun 16 '14 at 16:36
  • possible duplicate of [Valid Characters for JavaScript Variable Names](http://stackoverflow.com/questions/1661197/valid-characters-for-javascript-variable-names) – Alexei Levenkov Jun 16 '14 at 16:38
  • You can use many things in variable names `var π = Math.PI, r = 4;` then `2 * π * r === 25.132741228718345` – Paul S. Jun 16 '14 at 16:40

1 Answers1

1

Yes. It is simply the name of the variable. $ is a valid character for a variable name.

Magus
  • 14,796
  • 3
  • 36
  • 51