+ 2
Can't start variable names with numbers?
I learned here that variables can be alphanumeric. But whenever I am trying to create a variable starting with a number, it throws error. e.g: creating a variable called "9a". Is it an error or what?
3 Answers
+ 13
Hi @Chidananda-Sahoo :)
The characters that are allowed in Ruby (in most programming languages actually) when naming variables are letters (a-Z), numbers and underscores. They can contain numbers but they must not begin with numbers.
It's reasonable that you were unaware of this as it is not explained in Ruby's course. Actually, the only courses that do explain this are: Python, Javascript, Swift, PHP and C#. The rest of the courses offered in SL are missing this restrictions explanation.
I'd like to share with you the Ruby's naming conventions, you might find it useful: http://itsignals.cascadia.com.au/?p=7
+ 3
Naming variables is usually one of the first lessons a language teaches you when you learn it and one of the rules for naming variables, in all languages that I know of, is that you can't start a variable with a number.
Do also research on naming variables because there's a certain way a programmer must write variables.
Example (variables):
var btnStart;
//without me even explaning what my variable is for, you can already tell that this variable has something to do with a start button