JavaScript

Is JavaScript Case Sensitive

Yes, JavaScript is a case-sensitive language when it comes to accessing variables, constants, keywords, functions, and classes in a program. For instance, you have created two variables named “employee” and “Employee”. In JavaScript, both created variables are valid, distinct, and contain separate values. So, by utilizing the “employee” variable, you cannot retrieve the value “Employee” variable as they have different memory addresses.

Similar to other programming languages, JavaScript also comprises a set of styling guidelines known as the “Naming Conventions”. One such convention is to observe capitalization while naming a JavaScript class. The utilization of the JavaScript naming convention assists in improving the code readability and makes code maintenance easier.

This write-up will explain the case-sensitive nature of JavaScript with respect to its supported naming convention. So, let’s start!

JavaScript Names should be Descriptive

Any name assigned to a JavaScript class, function, or variable should be descriptive so that in the future, any other developer can easily understand the code without misinterpreting the name.

Here are some good and bad cases for naming a variable:

let data= "Alex"; // bad

let value= "Alex"; // bad

let name= "Alex"; // good

We will now move ahead and discuss the naming conventions for boolean type, constants, functions, and classes in JavaScript.

JavaScript Naming Convention for Boolean type variable

In JavaScript, the “boolean” variables are typically named by utilizing a prefix such as “has” or “is”. Adding a prefix helps to distinguish the boolean type variables from number and string data types.

For instance, the below-given four boolean variables are created according to the JavaScript naming convention for boolean type variable:

let isMember = false;

let isActive = true;

let hasHousingAddress = false;

let isOnline = true;

JavaScript Naming Convention for Constants

A JavaScript constant is an immutable type of value, which means that its value cannot be changed after initialization. The “const” keyword is utilized to declare constants in JavaScript, and its “name” should be assigned in capital (UpperCase) letters:

const COLOR =  "Yellow";

If the constant you want to create comprises more than one word, then separate them by using the underscore “_” as follows:

const SYSTEM_LANGUAGE = "en-us";

JavaScript Naming Convention for Functions

Functions in JavaScript use the lower “camelCase” naming convention, same as variables. You can also add a “verb” as a prefix with the function name that describes what the function does:

function getName(name) {

  return name;

}

function setName(name){

  employeeName= name;

}

JavaScript Naming Convention for classes

The “PascalCase” or the upper “CamelCase” naming convention can be applied to the classes name in JavaScript, where the first character of each word starts with an “UpperCase” character:

class EmployeeProfile{}

class Organization{}

In the above-given example, we have created two classes named “EmployeeProfile” and “Organization” by following the specified naming convention.

The next section will compare the behavior of JavaScript and HTML in terms of case sensitivity.

JavaScript case-sensitivity vs HTML case-sensitivity

In Web designing, HTML and JavaScript work together in such a way that objects are created using HTML tags, and then JavaScript assists in manipulating the added objects. Now, you may think that if JavaScript is a sensitive language, then HTML should also behave the same to maintain a stable interaction, but that’s not the case.

As HTML language was designed to have a “universal” nature where both computers and humans can easily read the web pages. In this language, all added letters are rendered the same. There is no need to specify the uppercase or lowercase letter for naming any HTML element, which signifies that HTML language is not case sensitive. However, JavaScript is case-sensitive because it is a “basic” language that follows a naming convention for the specified objects.

We have compiled the essential information related to case sensitive nature of JavaScript and its naming conventions. You can further explore it according to your requirements.

Conclusion

JavaScript is a case-sensitive language when it comes to accessing variables, constants, keywords, functions, and classes in a program. It also comprises a set of styling guidelines known as the “Naming Conventions”. The utilization of the JavaScript naming convention assists in improving the code readability and makes code maintenance easier. This write-up explained the case-sensitive nature of JavaScript with respect to its supported naming convention.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.