DEV Community

Yusuf
Yusuf

Posted on • Updated on

Common Programming Case Types

When you are working with computers, especially coding, you have to follow some set of rules to get your ideas working. In some other times, you are on your own to create your flow. However, since this work is a teamwork and chances are that someone else is reading your code, or you are reading someone else's code, there came in some conventions to follow.

One of the most important conventions to follow is when naming a variable. Everybody who has done coding knows that it is really not that easy to come up with a variable name, but there are conventions to follow when it comes to Case Types. Here is a list of most common Case Types:

  • Camel Case
  • Kebab Case
  • Snake Case
  • Pascal Case

Let's see each one of these in a bit more detail.

Note: We are not talking about how meaningful or long (or short) enough your variable needs to be, just simply learning about what different Case Types are.

Camel Case

This is when the variable name starts with a lowercase character and every subsequent word's first letter is capitalized.

thisIsAnExampleForACamelCase

Kebab Case

This is one of the easiest one to remember. Every character is lowercase and in between every word, you need to add a dash (-).

this-is-an-example-for-a-kebab-case

Snake Case

This one is very similar to Kebab Case. Every character is lowercase and in between every word, you need to add an underscore (_).

this_is_an_example_for_a_snake_case

Pascal Case

This one is when first letter of all words are capitalized, including the first letter and there is no space or any other character in between words.

ThisIsAnExampleForAPascalCase

What to use in JavaScript

Again, naming is a convention. However, I'm going to share some examples from Airbnb JavaScript Style Guide . According to that guide, here are what to use in JavaScript:

  • Avoid single letter names like x or q
  • camelCase for objects, functions, and instances
  • PascalCase for constructors or classes
  • Do not use trailing or leading underscores like _firstName, lastName_ or _fullName_
  • Acronyms and initialisms should always be all uppercased, or all lowercased like HTTPRequest or httpRequest

Top comments (0)