- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Case Sensitivity
JavaScript Statement & Expression
JavaScript Case Sensitivity
JavaScript is a case-sensitive programming language.
This means uppercase and lowercase letters are treated as different characters.
Example
Example
javascript
let name = "John";
let Name = "Emma";In this example, name and Name are two different variables.
What Case-Sensitive Means
Case-sensitive means JavaScript treats capital letters and small letters differently.
Example
javascript
let city = "London";
let City = "Paris";
let CITY = "New York";Here, all three variables are different because their letter cases are different.
| Variable | Value |
|---|---|
city | "London" |
City | "Paris" |
CITY | "New York" |
Variable Names are Case-Sensitive
JavaScript variable names must be written with the same uppercase and lowercase letters every time.
Example
javascript
let userName = "John";
console.log(userName);This works because the variable name is written correctly.
But this will not work:
Example
javascript
let userName = "John";
console.log(username);Here, userName and username are different names. JavaScript will not treat them as the same variable.
Function Names are Case-Sensitive
Function names are also case-sensitive.
Example
javascript
function showMessage() {
console.log("Hello JavaScript");
}
showMessage();This works because the function name is called correctly.
But this will not work:
Example
javascript
function showMessage() {
console.log("Hello JavaScript");
}
showmessage();Here, showMessage and showmessage are different names.
JavaScript Keywords Must Be Lowercase
Most JavaScript keywords are written in lowercase.
Example
javascript
let age = 25;
if (age >= 18) {
console.log("Allowed");
}Here, let and if are written in lowercase.
Wrong example:
Wrong Example
javascript
Let age = 25;
If (age >= 18) {
console.log("Allowed");
}This will not work because Let and If are not valid JavaScript keywords.
Object Property Names are Case-Sensitive
Object property names are also case-sensitive.
Example
javascript
let student = {
name: "John",
age: 21
};
console.log(student.name);This works because the property name is name.
But this will not work:
Example
javascript
let student = {
name: "John",
age: 21
};
console.log(student.Name);Here, name and Name are different property names.
camelCase in JavaScript
JavaScript developers commonly use camelCase for variable and function names.
In camelCase, the first word starts with a lowercase letter, and the next words start with uppercase letters.
Example
javascript
let firstName = "John";
let totalPrice = 1500;
let userEmailAddress = "john@example.com";
function calculateTotalPrice() {
console.log(totalPrice);
}camelCase makes names readable and clean.
Good Naming Examples
Use clear and consistent names.
Example
javascript
let userName = "Emma";
let userAge = 24;
let isLoggedIn = true;
let totalAmount = 2500;These names are easy to read and understand.
Complete Example
Complete Example
html
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Case Sensitivity</title>
</head>
<body>
<h1>JavaScript Case Sensitivity</h1>
<p id="result"></p>
<script>
let firstName = "John";
let FirstName = "Emma";
document.getElementById("result").innerHTML =
"firstName: " + firstName + "<br>" +
"FirstName: " + FirstName;
</script>
</body>
</html>Try It Yourself
Run the above example in the Try It Editor.
Try changing firstName to firstname in one place and check what happens.
Also try changing function names or object property names with different uppercase and lowercase letters.
Important Points
- JavaScript is case-sensitive.
name,Name, andNAMEare different identifiers.- Variable names must be written exactly the same every time.
- Function names are also case-sensitive.
- Object property names are case-sensitive.
- JavaScript keywords like
let,const,if, andfunctionshould be written in lowercase. - camelCase is commonly used for JavaScript variable and function names.
Conclusion
JavaScript case sensitivity means uppercase and lowercase letters are treated differently.
This rule applies to variables, functions, object properties, and keywords.
Understanding case sensitivity helps you avoid common errors and write cleaner JavaScript code.
