JavaScript Fundamentals (ES6)

Arrays are objects?

This is a little confusing but true that arrays are not a separate data type in javascript. All Arrays are objects. There are 9 kinds of data types in javascript. 1. Undefined​, 2. Null​, 3. Booleans​, 4. Numbers​, 5. Strings​, 6. Symbols​ 7. BigInts​, 8. Objects​, 9. Functions​. All others are objects like arrays, Date, etc.

Event Loop

Event Loop is a very confusing but easy thing in JavaScript. Actually, the event loop is more related to a browser. Browsers run each expression in a stack. If any expression takes time to execute for example API browsers send the expression to another section called web API. After loading data by web API browser send it to Task Queue. Here Event Loop comes. Event Loop has a very simple job. If the stack is completely clear event loop brings the first task from the task queue. That’s it, as simple as that.


If you are a programmer you might face some error while running your code. No matter how great you are at programming. We get errors for many reasons. But what if we can give errors. Suppose, you need your user’s information including username, email, and so on. But the users intentionally or unintentionally forget to give their username. If you don’t get the username your code will not execute properly. But using Try……Catch we can check whether the user gives the proper information or not. If not we will give an error message to the user. The important thing is our whole code will not stop working browser will skip the error and run the rest of the code.

try {// if error here} catch (err) {// error handling}// code will run

Clean Code

Writing clean code is very important for any type of programmer. Clean code is easy to read and debug. Only you will not read your code rather you team member will also read your code. So, It is important that not only you but also others can also understand your code. Here is an example of clean code. Both will give the same output but the 2nd one is easy to read and understand.

if (n < 0) {alert(`Power ${n} is not supported`);}
if (n < 0) {alert(`Power ${n} is not supported`);}

Cross Browser Testing

If you are a web developer or trying to be a web developer, you definitely want your website to work properly in every browser. But all browsers are not the same. For example, older browsers don’t support all the latest, shiniest CSS and JavaScript features. All users don’t use the same browser. So, you need to test your website with different browsers. And this is simply called cross-browser testing.

Evolution of JavaScript

JavaScript officially released 9 editions. The First edition was released in 1995 and the last edition of javascript was released in 2018. The most controversial edition is ES6 and which was released in 2015. Javascript introduced the let and const variable in ES6. There is another edition, but it was not released which name is ECMAScript 4.

Variable scope

There are 2 types of scope local and global. A global scope variable can be accessed from anywhere. But if I declare one variable in a function with let or const, I can not use that variable outside of that function. This is called the local variable. We can make a variable global without assigning it with var, let, or const. let's see the example below —

// x can’t be used here// z can be used herefunction () {z = 20;let x = 10;// x can be used here}// x can’t be used here// z can be used here

Default Parameters

Function default parameter was introduced in ES6. We can assign a default value of any parameters. The default value can be an empty object, array, or any other data type. If we set a default and don’t give any value for the parameters function will take the default value. But if we don’t set the default value and also don’t give a value for the parameters then we will get an error. Here is an example of default parameters -

function add (x = 10, y = 5) {// code here}add();

Spread Operator

The spread operator is one of the most useful things in javascript. We can use a spread operator with both array and object. Using spread operator we can combine two or more arrays or objects together. Suppose, you have an array call animals and you want to combine it with another array called birds, here the spread operator will help you out.

let animal = [“dog”, “cat”];let bird = […animal, “Doyel”, “crow”]; // [“dog”, “cat”, “Doyel”, “crow”]

Arrow Function

The function is the most important topic of any programming language. In JavaScript, we can create functions in two different ways. One is using the function keyword, it is the oldest one. Another is the arrow function here we don’t need the function keyword. It is way easier than the older one. Here is an example below.

function add (x, y) {
return x+y;
let arrow = (x, y)=> {return x+y;}

Hi there, I am a Junior Web Developer. I love to build interactive websites and travel around the world.