Basic Programming Tutorials

JavaScript Case Sensitive

Welcome to the JavaScript tutorial, we already discussed JavaScript Syntax, and today we will discuss about JavaScript case sensitive, yes JavaScript is a case sensitive. Before stepping into JavaScript case sensitive, tell me do you know what is case sensitive? Three cheers for yes, and for no, don’t worry, we will find it, what is the meaning of case sensitive,  and then will see how it will help us to understand case sensitivity in JavaScript.


Case sensitive

It is a way or a program to differentiate between lower case letters and upper case letters.

For example:

A program will treat lower case letters such as “a” as a only , and Upper case letters like “A” as A only.

JavaScript Case sensitive

Like case sensitive program, JavaScript is also a case sensitive language, it means lower case letter will be treated as lower case and upper case letters will be treated as upper case only. JavaScript will not interpret lower case to upper case or upper case to a lower case letter.

 

JavaScript case sensitive – Examples

Let’s understand JavaScript case sensitive topic with the simple example, we have written a small program to add two variables, find out what it will show and how JavaScript treats variables:

<html>

<head></head>

<body>

<script>

y= 5;

Y = 10;

result1= y + y;

result2 = y + Y;

document.write(result1 + "<br>" + result2 );

</script>

</body>

</html>

When you will run this program, then you will see results:

10

15

Now let’s see where we stand with our  topic JavaScript case sensitive, if you will see our program, then can easily find that we have used “ y”(lower case) and “Y”(Upper case) variables that store the value 5 and 10. Now let’s find out, what results we got in our example.

10 and 15, why so? Let’s see

JavaScript interpreted “y” as y and “Y” as Y.

  • 10 -We got 10( 5 +5 ), because variable y has the value 5.
  • 15 – We got 15(5 + 10), because variable y has the value 5 and variable Y has value 10.

Try to run this program, and clear the important thing that the “ JavaScript is case sensitive”.

Note: Always Use document.write() for testing purpose only.

Conclusion

We have just covered the topic ‘ JavaScript case sensitive’ and hopefully you have cleared your doubt. Just remember that JavaScript is a case sensitive language and will not show proper result, if it will misinterpret the code.