javascript

Case Sensitivity

JavaScript is case-sensitive — every letter's case matters. Learn how case sensitivity affects variables, functions, keywords, built-ins, and DOM methods, plus naming conventions that keep your code consistent.

8 min read 8 sections Tutorial
Share

JavaScript Case Sensitivity

JavaScript Case Sensitivity

JavaScript is a case-sensitive language. This means that the JavaScript engine treats every uppercase and lowercase letter as a distinct character. name, Name, and NAME are three completely separate identifiers — they have nothing to do with each other.

This applies everywhere: variable names, function names, object properties, class names, keywords, and all built-in browser APIs.

One of the most common beginner mistakes

Typing Console.log() instead of console.log() or document.GetElementById() instead of document.getElementById() causes a ReferenceError or TypeError. The engine sees these as completely different names.

Identifiers

Variable, function, and class names are all case-sensitive. user, User, and USER are different.

Keywords

JavaScript keywords are all lowercase: let, const, if, return. Writing Let or RETURN is a SyntaxError.

Built-ins & APIs

console.log, document.getElementById, Math.random — every character's case is fixed.

Conventions

camelCase for variables/functions, PascalCase for classes, UPPER_SNAKE for constants.

Case Sensitivity in Identifiers

Case Sensitivity in Identifiers

An identifier is any name you create — for a variable, function, parameter, class, or object property. Every identifier is case-sensitive. The engine compares character by character, and a single different case means a completely different identifier.

javascript
1// These are THREE different variables
2let score = 100;
3let Score = 200;
4let SCORE = 300;
5
6console.log(score); // 100
7console.log(Score); // 200
8console.log(SCORE); // 300
9
10// Same applies to functions
11function greet() { return 'hello'; }
12function Greet() { return 'HELLO'; }
13
14console.log(greet()); // 'hello'
15console.log(Greet()); // 'HELLO'
16
17// And object properties
18const user = {
19 name: 'Alice',
20 Name: 'Bob', // different property!
21 NAME: 'Carol' // yet another!
22};
23
24console.log(user.name); // 'Alice'
25console.log(user.Name); // 'Bob'
26console.log(user.NAME); // 'Carol'

Never define two identifiers that differ only by case

While JavaScript allows let data and let Data in the same scope, never do this. It causes extreme confusion, makes code unmaintainable, and is virtually impossible to read correctly at a glance. Use meaningful, distinct names instead.

Keywords Are Always Lowercase

Keywords Are Always Lowercase

All JavaScript reserved keywords are lowercase. They are fixed — you cannot change their case. Writing Let, Const, IF, or RETURN causes a SyntaxError because the engine doesn't recognise them as keywords.

javascript
1// ✅ Correct — all keywords lowercase
2const PI = 3.14159;
3let count = 0;
4
5function add(a, b) {
6 return a + b;
7}
8
9if (count === 0) {
10 console.log('Zero');
11}
12
13for (let i = 0; i < 3; i++) {
14 console.log(i);
15}
16
17// ❌ These ALL cause SyntaxError:
18// Const x = 5;
19// Let y = 10;
20// IF (true) { }
21// RETURN 42;
22// Function foo() { }
23
24console.log(add(2, 3)); // 5
Correct ✅Wrong ❌Error Type
letLet / LETSyntaxError
constConst / CONSTSyntaxError
varVar / VARSyntaxError
if / elseIf / IF / ElseSyntaxError
for / whileFor / WhileSyntaxError
functionFunction / FUNCTIONSyntaxError
returnReturn / RETURNSyntaxError
classClass / CLASSSyntaxError
import / exportImport / ExportSyntaxError
true / false / nullTrue / False / NullSyntaxError

Built-in APIs and Case

Built-in APIs and Case

All JavaScript built-in objects, methods, and browser APIs have fixed, case-sensitive names. The most common mistakes happen with the global console object and DOM methods.

javascript
1// ✅ console — all lowercase
2console.log('hello');
3console.warn('warning');
4console.error('error');
5console.table([1, 2, 3]);
6
7// ❌ These FAIL — TypeError: Console is not defined
8// Console.log('hello');
9// CONSOLE.LOG('hello');
10
11// ✅ Math object — capital M, lowercase methods
12console.log(Math.random()); // 0 to 1
13console.log(Math.floor(4.9)); // 4
14console.log(Math.max(1, 5)); // 5
15console.log(Math.PI); // 3.14159...
16
17// ❌ Wrong casing for Math
18// console.log(math.random()); // ReferenceError
19// console.log(Math.Random()); // TypeError
20
21// ✅ Array methods — all lowercase
22const nums = [3, 1, 2];
23nums.sort();
24console.log(nums); // [1, 2, 3]
25
26// ❌ Wrong
27// nums.Sort(); // TypeError

camelCase vs PascalCase vs UPPER_CASE

Naming Conventions

JavaScript doesn't enforce naming conventions — the engine doesn't care if you use camelCase or snake_case. But the community has settled on consistent conventions that every developer follows. Using the right convention makes your code immediately readable to any JavaScript developer.

camelCasePascalCase
Used for variables and function namesUsed for class names and constructor functions
First word lowercase, each subsequent word capitalisedEvery word starts with a capital letter
Examples: userName, getUserData, isLoggedIn, fetchPageCountExamples: User, UserProfile, HttpRequest, EventEmitter
Most common style in JavaScript — use it for everything that isn't a class or constantWhen you see PascalCase, you immediately know it's a class or component (React)
javascript
1// camelCase — variables and functions
2let userName = 'Alice';
3let isLoggedIn = true;
4let totalItemCount = 0;
5
6function getUserProfile(userId) {
7 return { id: userId, name: userName };
8}
9
10function calculateTotalPrice(items) {
11 return items.reduce((sum, item) => sum + item.price, 0);
12}
13
14// PascalCase — classes and constructor functions
15class UserAccount {
16 constructor(name, email) {
17 this.name = name;
18 this.email = email;
19 }
20
21 getDisplayName() {
22 return this.name;
23 }
24}
25
26// UPPER_SNAKE_CASE — constants that never change
27const MAX_RETRY_COUNT = 3;
28const API_BASE_URL = 'https://api.example.com';
29const DEFAULT_TIMEOUT_MS = 5000;
30
31// Usage
32const account = new UserAccount('Bob', 'bob@example.com');
33console.log(account.getDisplayName()); // 'Bob'
34console.log(getUserProfile(1)); // { id: 1, name: 'Alice' }
35console.log(MAX_RETRY_COUNT); // 3
WhatConventionExample
VariablescamelCasefirstName, isActive, itemCount
FunctionscamelCasegetUserData(), handleClick(), formatDate()
ClassesPascalCaseUser, EventEmitter, HttpClient
Constants (fixed values)UPPER_SNAKE_CASEMAX_SIZE, API_URL, DEFAULT_LIMIT
Private fields (convention)_camelCase_userId, _cache, _isReady
Boolean variablescamelCase with is/has/canisLoggedIn, hasError, canEdit
Event handlerscamelCase with on/handleonClick, handleSubmit, onKeyDown
React componentsPascalCaseNavBar, UserCard, LoginForm

Common Case Mistakes

Common Case Mistakes to Avoid

javascript
1// ❌ MISTAKE 1: Wrong console casing
2// Console.log('hello'); // ReferenceError: Console is not defined
3// console.Log('hello'); // TypeError: console.Log is not a function
4console.log('✅ console.log works'); // correct
5
6// ❌ MISTAKE 2: Wrong Math method casing
7// Math.Round(4.5) // TypeError: Math.Round is not a function
8console.log(Math.round(4.5)); // ✅ 5
9
10// ❌ MISTAKE 3: Wrong JSON method casing
11// JSON.Parse('{"a":1}') // TypeError
12// JSON.Stringify({ a: 1 }) // TypeError
13console.log(JSON.parse('{"a":1}')); // ✅ { a: 1 }
14
15// ❌ MISTAKE 4: Wrong array method casing
16const arr = [1, 2, 3];
17// arr.Map(x => x * 2) // TypeError
18// arr.Filter(x => x > 1) // TypeError
19console.log(arr.map(x => x * 2)); // ✅ [2, 4, 6]
20console.log(arr.filter(x => x > 1)); // ✅ [2, 3]
21
22// ❌ MISTAKE 5: Typo creates a new variable silently (var era)
23// var userName = 'Alice';
24// console.log(username); // undefined — not an error with var! Bug.
25
26// ✅ With let/const this IS an error (helpful)
27const firstName = 'Alice';
28// console.log(firstname); // ReferenceError — caught immediately!

Use TypeScript or a linter to catch case mistakes

TypeScript will instantly flag Console.log or Math.Round as type errors before you even run your code. ESLint with the no-undef rule also catches references to undefined names. Both tools eliminate the entire class of case-typo bugs.

Test Your Knowledge

Test Your Knowledge

Quick Check

What will happen when you run: Console.log('hello');

Quick Check

Which variable declaration will cause a SyntaxError?

Quick Check

What naming convention should you use for JavaScript class names?

Quick Check

Are count and Count the same variable in JavaScript?

Quick Check

Which of the following is the correct way to call the Math rounding method?

Quick Reference

Case Sensitivity Quick Reference

Pro Tips
  • 1JavaScript is 100% case-sensitive — every letter in every identifier matters.
  • 2All keywords are lowercase: let, const, if, else, for, while, return, class, import.
  • 3console is all lowercase. Math and JSON start with uppercase. NaN, Infinity, undefined are lowercase.
  • 4Use camelCase for variables and functions: getUserData, isLoggedIn, totalCount.
  • 5Use PascalCase for classes and constructors: User, EventHandler, HttpClient.
  • 6Use UPPER_SNAKE_CASE for top-level constants: MAX_SIZE, API_URL, DEFAULT_TIMEOUT.
  • 7Use TypeScript or ESLint to catch case typos instantly — before they become runtime bugs.
  • 8Never create two identifiers in the same scope that differ only by case — it is a maintenance nightmare.
Continue Learning

Statements & Semicolons

How statements work, when semicolons are required, and ASI pitfalls.

Comments

Single-line, multi-line, and JSDoc comments — how and when to use them.

Variables

let, const, var — declarations, scope, hoisting, and when to use each.

Functions

Function declarations, expressions, arrow functions, and scope.

You understand JavaScript case sensitivity!

You now know that JavaScript distinguishes every letter's case in identifiers, keywords, and built-in APIs. You also know the community naming conventions — camelCase, PascalCase, and UPPER_SNAKE_CASE — that make JavaScript code consistent and readable.

Try it in the Javascript Compiler

Run and experiment with Javascript code right in your browser — no setup needed.

Continue Learning