Now that PHP syntax has been converted to Node.js in the previous chapter, we can turn our attention to variables, which are a little more interesting and complicated to convert.
In PHP, a variable name always starts with a dollar sign ($).
$colors are PHP
variable names, but
colors are not. In Node.js, a variable
name may start with a dollar sign ($), but does not have to. So, in
colors are all valid Node.js variable
However, in Node.js, even though it is perfectly legal, it is a widely
accepted common practice to avoid variable names that begin with a dollar
sign ($). It is so widely accepted that Node.js code that uses variable
names that start with a dollar sign ($) looks very, very strange to Node.js
developers. To accommodate this practice, it is recommended that PHP
variable names be converted to Node.js variable names by removing the dollar
sign ($). For example, the PHP variables
should be converted to the Node.js variables,
The allowed characters in a PHP variable name is a subset of the allowed characters in a Node.js variable name. It is recommended that variable names, excluding the initial dollar sign ($) for PHP variables, begin with an alphabetic character of either case, that is, a to z or A to Z, and have the remaining characters be zero or more characters that are alphabetic characters of any case (a to z or A to Z), underscores ( _ ), or digits (0 to 9). ...