Rules of declaring variable names
Variable names can be freely named within some rules. Today, let's look at the rules for declaring variable names.
1. Variable names include only alphanumeric characters and underbar (_).
2. Variable names distinguish between upper and lower case letters.
3. Variable names distinguish between upper and lower case letters.
4. Reserved words can not be used. (Eg, if, for, while etc.)
Types of reserved words
abstract |
case |
continue |
extends |
for |
import |
long |
private |
static |
throw |
var |
boolean |
catch |
default |
false |
function |
in |
native |
protected |
super |
throw |
void |
break |
char |
do |
final |
goto |
instanceof |
new |
public |
switch |
transient |
while |
byte |
class |
double |
finally |
if |
int |
null |
return |
synchronized |
true |
with |
case |
const |
else |
float |
implements |
interface |
package |
short |
this |
try |
For example, the following variables are not allowed:
1hi = "hello"; wrong since it begins with a number. if = "hello"; wrong since it uses a reserved words. sos+dfdf = "hello"; wrong since is has +
Let's wrap up this lesson here ^^