Why you should write clean code as a JavaScript Developer?

Jan 23, 2022ยท

2 min read

Play this article

Hello Folks ๐Ÿ‘‹

What's up friends, this is SnowBit here. I am a young passionate and self-taught developer and have an intention to become a successful developer.

Today, I am here with something important for you as a JavaScript Developer.

Why you should write clean code as a JavaScript Developer

Writing clean code improves the maintainability of the application and make the developer productive. Unfortunately, some developers are unaware of this language feature.

๐ŸŒŸ Make Use of Arrow Functions

Arrow functions provide the abridged way of writing JavaScript.

The main benefit of using arrow functions in JavaScript is curly braces, parenthesis, function, and return keywords become completely optional; and that makes your code more clear understanding.

The example below shows a comparison between the single-line arrow function and the regular function.

// single line arrow function
const sum = (a, b) => a + b

// Regular Function
function sum(a, b) {
    return a + b;

๐ŸŒŸ Use Template Literals for String Concatenation

Template literals are determined with backticks`

Template literals can contain a placeholder, indicated by a dollar sign and curly braces {}


We can define a placeholder in a string to remove all concatenations.

// before
const hello = "Hello"
console.log(hello + " World")

// after
const hello = "Hello"
console.log(`${hello} World`)

๐ŸŒŸ Spread Syntax

Spread Syntax(...) is another helpful addition to ES6.

It is able to expand literals like arrays into individual elements with a single line of magic code. ๐Ÿ”ฎ

const sum = (a, b, c) => a + b + c
const num = [4, 5, 6]
console.log(`Sum: ${sum(...num)}`)

๐ŸŒŸ Object Destruction

Object destruction is a useful JS feature to extract properties from objects and bind them to variables.

For example, here we create an object with curly braces and a list of properties.

const me = {
    name: "SnowBit",
    age: 15,
    language: "JavaScript"

Now letโ€™s extract name and age property values and assign them to a variable.

const name = me.name
const age = me.age

Here, we have to explicitly mention the name and age property with me object using dot(.), and then declare the variables and assign them.

We can simplify this process by using object destruction syntax.

const {name, age} = me
console.log(name, age)

Thank you for reading, have a nice day! Your appreciation is my motivation ๐Ÿ˜Š