Some important things for JavaScript

Today we discuss some important things for JavaScript like coding style, comments, arrow function, and so on.

Coding Style: Clean code uses is very important in JavaScript because it’s easier to read and understand.Some coding standards of javascript.

1. Variables and function names must be camelCase.

2.Always try to use const and let instead of var.

3. Always use semicolons(;).

4.Use curly brace in the same line after space.

5.Use a space between parameters.

6.Don’t use space between the function name and parentheses.

7. Use Spaces around operators

8.Use colon plus one space between each property and its value.

9.Use quotes around string values, not around numeric values.

10. Use A space between arguments.

Comments: Comments are very important in real life as well as in coding life. JavaScript comments can be used to explain JavaScript code, and to make it more readable. There are two types of comments.

1. Single line comments: Single line comments start with two froward slash characters //. You can write anything between // and the end of the line because this text will be ignored by JavaScript.

2. Multi-line comments: You can use Multi-line comments in the code. Multi-line comments start with a forward slash and an asterisk /* and end with an asterisk and a forward slash */. You can write anything between /* and */ this text will be ignored by JavaScript.

Primitive Values: There are two types of data in JavaScript- primitive values and objects. There are six types of primitive values undefined , null , boolean , number , string and symbol .

Typeof(): If you want to know what is the data type of given value, then you should use typeof operator. Here is the list of all the types:

1. undefined

2. object

3. boolean

4. function

5. number

6. string

7. symbol

Arrow Function: Are you bored to use the traditional function? Then you can use arrow function. Arrow function is very simple and shorter than the traditional function. Arrow function is one of the features introduced in the ES6 version of JavaScript.

Spread Operator: Spread means extend over a large or increasing area. The spread operator is used to expand or spread an iterable or an array. The spread operator is a new addition of the ES6 version of JavaScript.

in the above ... is a spread operator


Default Parameters: In JavaScript, a parameter has a default value of undefined. If you don’t pass the arguments in the function, its parameters will have the default values of undefined. This will help you to avoid errors.

in the example, the default value of the message parameter is undefined.

Variable Hoisting: You can be used a variable before it has been declared. All variable and function declarations are hoisted to the top of their script. In JavaScript put function declarations into memory, that’s why you can use a variable before you declare it in your code.

In the above example, variable a is used before declaring it. And the program works and displays the output 5. The program behaves as:

Error Handling: If you are a programmer, you are definitely familiar with errors. The error because of our mistakes, an unexpected user input, an erroneous server response, and for a thousand other reasons. There are a method to catch the errors. The try...catch syntax allows us to “catch” errors so the script can, instead of dying, do something more reasonable.

At first, the code in try {...} is executed. If there were no errors, then catch (err) is ignored. If an error occurs, then the try execution is stopped, and control flows to the beginning of catch (err).

Destructuring: Destructuring is the new addition of ES6. Destructuring helps you to “unpack” arrays or objects into a bunch of variables.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store