JavaScript is a dynamic language. This makes JavaScript a supercool language to start. However, It is very hard to write better and safe code. One small mistake can lead to a bigger issue. Error handling plays a vital role to reduce the number of bugs. If you handle error elegant way, it will save a lot of time in the future. So the bigger question is how you should handle the error.

Let’s take one example.

const express = require("express")
const app = express()
app.get("/", (_, res) => res.end("OK"))

app.listen(80)

The above code is a sample code written in nodejs on an express framework. In this code, I am trying to run a server at port 80.

Questions:

  1. What if we know that port 80 is already taken by some other app and we try to run the above code.
  2. How do we know what will happen?
  3. Will it run or break with some error?

The output is very unclear while seeing this code. Even you want to handle an error, you may have to read the documentation. But don’t worry, just like any natural language. The programming language has some grammar.

ECMA, There is no particular specification/standard mentioned. However, the JavaScript community follows certain coding guidelines.

#javascript

How to Write Better and Secure JavaScript Code
1.20 GEEK