Do’s and don’ts in JavaScript

Today we will provide you the list of the do’s and don’ts in JavaScript as per the Google JavaScript Style Guide. When we are working with the real project at that time we have to follow the standard programming guidelines which will help us to write the error free codes.

Do’s and don’ts in JavaScript for newbies, JavaScript naming conventions: do’s and don’ts, What are the do’s and don’ts when coding in JavaScript?, JavaScript Norms.

List of the Do’s and don’ts in JavaScript

  1. Use const and let
  2. Local Variable Declaration
  3. File Name
  4. Package Name
  5. Class Name
  6. Method Name
  7. Constant Name
  8. Parameter Name

1. Use const and let

Declare all local variables with either const or let. Use const by default, unless a variable needs to be reassigned. The var keyword must not be used.

2. Local Variable Declaration

Declare the local variables with either let or const keyword. Use const by default if the variable doesn’t need to be reassigned.

Local variable names are written in lowerCamelCase.

One variable per declaration. (For example: let a = 1 , b = 2 // It’s not good practice.)

3. File Name

File names must be all lowercase and may include underscores ( _ ) or dashes ( - ), but no additional punctuation. Follow the convention that your project uses.

4. Package Name

Package names are all lowerCamelCase. (For example, my.testExample.deepSpace, but not my.testexample.deepspace or my.test_example.deep_space)

5. Class Name

Class names, interface names, typedef, and record names are all UpperCamelCase.

6. Method Name

Method names must be lowerCamelCase.

7. Constant Name

Constant names should be all UPPER_CASE, separated by underscores.

8. Parameter Name

Parameter names are written in lowerCamelCase.

We have listed a couple of points here. Refer Google JavaScript Style Guide for more points.

Thank you for reading. Happy Coding!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *