Is JavaScript Case Sensitive?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Yes, JavaScript is a case-sensitive language, name of keywords, variables, functions, and other identifiers are strictly case-sensitive in Javascript.

What is Case Sensitivity?

Case sensitivity means any case difference between two words makes them different from each other. Here is an example to understand case sensitivity in Javascript-

Output

Above, we declared a variable myVal and tried to access it by writing its name myval. As a result, we get an error myval is not defined, this happens because of the case difference between the declared variable name myVal and myval, which makes them different from each other.

Why is Case Sensitivity So Much More Important in JavaScript?

In Javascript, codes are read by the Javascript engine the same as it's written by us. For example- If we declare a variable myName, Javascript engine will read it myName exactly, not myname or MYNAME.

To use or access any identifier in Javascript, we have to write their name the same as given during declaration, making any case difference will cause an error. That's why case sensitivity so much more important in Javascript.

Example

Output

Above, we declared a greet function and then called it by passing the required parameter. As a result, we printed the Welcome ABC on the console. Then again, called the function by changing its first word in the uppercase. As a result, it printsReferenceError: Greet is not defined on the console, this happens because the function we declared is greet, and we are trying to access Greet, which is not defined yet. This verifies that case sensitivity is so much more important in JavaScript.

Why is JavaScript Case Sensitive, But HTML isn’t?

HTML is a markup language rendered by the browser. During the rendering process, HTML tags and attributes get converted from UPPERCASE to lowercase, because of that HTML is case insensitive.

For example- <body> tag in HTML can be written in small case <body></body> or in upper case like- <BODY></BODY>.

In Javascript, codes are read by the Javascript engine the same as it's written by us, which means to use or access any identifier, we have to write their name, the same as given during the declaration. For example- the onclick event listener in Javascript, it can be written only onclick, which is in the small case, making any case difference in writing onclick will cause an error. That's the reason JavaScript is case sensitive, but HTML isn’t.

Example

In this example, will declare a function and try to access it by making a case difference in its name-

Output

Above, we declared an add function and called it by passing the required parameters. As a result, we printed the 30 on the console. Then again, we called the same function but changed the first word in uppercase, like- Add. As a result, the console will show the ReferenceError: Add is not defined , this happened because we changed the first function add in uppercase (Add), but making a case difference makes both different from each other. This behavior of Javascript, after making a case difference, verifies that Javascript is case-sensitive.

Conclusion

  • Case sensitivity means any case difference between two keywords, variables, functions, or identifiers names will make them different from each other
  • JavaScript is a case-sensitive programming language.
  • HTML(hypertext markup) is a case-insensitive mark-up language.

See Also