Every JS Beginners must know
As a beginner with a new language we should focus on some really very important thing to make things easy, today’s post we’ll discuss about some basic things that one must know to make his or her life with JS a bit easier. Let’s get started.
As a programmer our code must be clean and readable. Sometimes we have to look back our code to make some changes, update things, remove errors in a lot of similar type conditions, if you can’t get into that spot of your code, then it’s a huge problem. The Readability of a code is a must for a good programmer. Now, the burning question is, How to make our Coding Style readable and clean?
The fun part is “There are no “you must” rule here. Everyone have their own preferences.
Use of Curly Braces, most JS programmers writes the opening of curly braces on the same line and the corresponding code on the new line, like below example. In these conditional example, we can see that that the first string was way long, and second string is better because we split them.
if (condition) {
let string = `No one likes to read long horizontal lines of code`
let string2 = `
No one likes to read long horizontal lines of code,
Here it looks okay and very eye soothing`
//this and that and so on
}
So, we must follow some convention for coding.
Next Important thing is comments, formerly we told you that readable code is a feature of good programming. Let’s assume you wrote a function that handles something, but you forget what it is. If you commented on that particular function, you can get it. Not only this, when your Team Leader wants to know about your code, without comment, it’ll be tough. But as a Beginner we do some mistakes regarding writing comments.
Complex code; //this and that and so on and it will return this
In This above example, we see that some of us, the beginners tried to explain a lot in the comments, which is somehow unnecessary, Comments should be minimal like in two or three explanatory words
Now let’s look forward to Error Handling. Programmers are human being, they are not aliens, aren’t they? Error Handling is one of the important thing in real-world coding projects, what should we do?
There’s a syntax try…catch that catches errors on that block so that the script don’t stop eventually and do something more reasonable.
try {
//code
} catch (err) {
//error handling}
Firstly, the code in the try block executed, if there were no errors the catch will totally be ignored. If there is, then the try block will be stopped and catch block will be executed to handle the errors.
Just some random basic things which we must know at the very beginning in diving into the ocean of JavaScript.
Happy Coding.