It is bad practice to place variables in strings, whatever the type of variable.
When we say "in strings", we explicitly mean "in string literals", i.e. something that you have typed in between quote characters (" or '). The variable istelf can be used wherever a string literal would be used - just don't put it inside quotes.
When a variable is not used in a string it is expanded, and the value of the variable is used in the expression. If the variable is in quotes this may or may not happen, depending in the variable value and type.
Some variable types (arrays, objects) simply don't work in strings at all. Undeclared variables will return an empty value when not used in strings, but the variable name will be used as-is when used in strings.
See this example:
Code:
"Undeclared=$Undeclared" ?
"Undeclared="+$Undeclared ?
This displays the following:
Quote:
Undeclared=$Undeclared
Undeclared=
Now, one of those results must be wrong!
Also note, when you are using SetOption("Explicit","ON") undeclared variabled will not be caught if they are present in strings.
Not declaring variables in strings future-proofs your code, and means that other people can use your scripts without changing it.
Variables in strings is not forbidden, and support for it is likely to be around for a while. However if you get into the habit of not placing variables in strings you will write code which is more portable, easier to debug and less prone to odd failures.