10 Topics That You Should’ve Know as a Developer

Iffatunnessa
3 min readMay 6, 2021

Describing some tips and tricks about code writing, ES6 and many more.

Primitive values

Primitive values are not functions or objects and they cannot be altered. That means they are immutable. These are like constants.

  • String
  • Number
  • Boolean
  • BigInt
  • Symbol
  • Undefined
  • Null

Try-Catch Function

Our Scripts can have errors due to our mistakes, unexpected values or incorrect server response. So, we need to handle those errors using functions like try-catch.

try {    // our code...  } 
catch (error) { // error handling, print messages etc }

It can be explain with this pseudo code:

  1. Try block: in this block, our codes are written and compile and run it as usual.
  2. Catch block: If there is some errors in the try block it’ll capture it on error variable.
  3. Otherwise, it’ll skip the catch block.

We can handle the errors by giving some alerts with dialogue box or error text for letting know the users.

Comments

Comments are important to hide any piece of code from compiler. It’s very easy to comment out your codes by using // or /*…*/.

Double Slashes (//) has been used for single line commenting and Slash and star (/*…*/) are used for multiple line commenting.

//This is a single line comment.
/* I just wanna show you
that it's very necessary to
comment some codes out. */

Sometimes we use comments for understanding what piece of code it is about. It helps our team mates to know what this function is doing here. Also, 4 years of experience taught me that it is very helpful for yourself too.

Multiple lines shouldn’t be commented with double slash as the single line. It’s a Bad Commenting style.

Syntax

Coding style is very important while testing it out or we are a part of a team. Syntax should be clean and spacious. When I was a beginner, my professors said this to me to use shortcuts of compilers that helps them to read my codes. I thought why should I use extra spaces here! Now, I know that it’s necessary to put my code into the rules or syntax for make it readable. But don’t make extra new lines into your codes that’s a bad habit.

Example #1:

var i;
for (i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}

Example #2:

if (hour < 18) {
greeting = “Good day”;
} else {
greeting = “Good evening”;
}

but curly braces are not necessary in some cases, like:

if(!isTrue){console.log("It is true");} 

ShortCut for VSCode: Ctrl+Alt+f

ES6

ECMAScript 6 has made JavaScript easier and standard. It was published in 2015, and is also known as ECMAScript 2015.

Block Binding

Block binding is a way to declare your variable. Most C-based language have their declaration area. But ES6 gives you controlling scopes to declare your variable in your own way.

Var Declarations and Hoisting

var declaration can be done in any place that you want but in basic JavaScript wherever you declare it, it’ll be accessible from everywhere like a global declaration.

if(condition){
var name = 'Adam';
}
else{
//your code ...
}

Even if we declare var ‘name’ in the ‘if’ block, it’s accessible in ‘else’ block also. Sometimes we don’t want to do it.

Block Level Declaration

Block level declaration is a thing that over comes the problem with var declaration. It can be inside a function or outside of a function. That means either globally and locally.

Let Declaration

let declaration is as same as the var declaration. But the limit of this variable will be within the curly braces before it. let variables can be changed and controlled. So, we have to add it in the first lines on the block so that it’s accessible to the entire block.

Constant Declaration

It’s same as the let declaration but constant values are declared here. You can’t the value between the curly braces where you have declared it.

if(condition){
const name = 'Adam'; //name can't be changed here
let count = 5;
count++; // count = 6;
}
else{
//name and count is not available
}
//name and count is not available

--

--