Niraj Chauhan

Niraj Chauhan

#father#husband#SoftwareCraftsman#foodie#gamer#onepiece#naruto

Javascript Naming Conventions

Many times we face situations in projects for naming our files, variables or classes. Here is the convention I am sharing which I follow in my projects of Javascript.

Filenames:

This should be kebab-case, words to be small case and - separated

routes.js
product-service.js

Variables:

Variables in Javascript should camel-case.

let firstName = 'Niraj';
var age = 26;

Functions:

Again this will be camel-case.

var getName = () => {};
function setName(){
  // YOUR CODE
}

Classes:

Classes should be pascal-case.

class User{}
class UserController{}

In react I have seen many projects where developers rename the filename of components to be pascal-case which is not wrong but that’s the way developers bring change to the programming world.

javascriptreactnodejsnamingconventions