JS-Capital Letters

It is extremely important to be aware that javascript makes a sharp distinction between capital and lowercase letters.

Javascript does not consider a variable named myvalue to be the same as a variable named MYVALUE.

Consider these examples:

Example 1
Example 2 
<html>
<head>
<title>My Page</title>
</head>
<body>
<script>
myvalue=2;
myvalue=5;
result=myvalue+myvalue;
document.write(result);
</script>
</body>
</html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<script>
myvalue=2;
MyValue=5;
result=myvalue+MyValue;
document.write(result);
</script>
</body>
</html>
 


The output of example 1 would be 10 (5+5).

The output of example 2 would be 7 (2+5).





The best advice is to use the same syntax on all variables.

Either write all variables in small letters, start with one capital letter or write all variables in capitals.

Which syntax you chose is not important 
- as long as you chose just one!

Post a Comment

Previous Post Next Post