As we mentioned before, a variable’s name is like a tiny comment. Even though there isn’t much room, any extra information you squeeze into a name will be seen every time the variable is seen.
So if there’s something very important about a variable that the reader must know, it’s worth attaching an extra “word” to the name. For example, suppose you had a variable that contained a hexadecimal string:
string id; // Example: "af84ef845cd8"
You might want to name it
hex_id instead, if it’s important for the reader
to remember the ID’s format.
If your variable is a measurement (such as an amount of time or a number of bytes), it’s helpful to encode the units into the variable’s name.
var start = (new Date()).getTime(); // top of the page ... var elapsed = (new Date()).getTime() - start; // bottom of the page document.writeln("Load time was: " + elapsed + " seconds");
There is nothing obviously wrong with this
code, but it doesn’t work, because
getTime() returns milliseconds, not
_ms to our variables, we can make everything
var start_ms = (new Date()).getTime(); // top of the page ... var elapsed_ms = (new Date()).getTime() - start_ms; // bottom of the page document.writeln("Load time was: " + elapsed_ms / 1000 + " seconds"); ...