JavaScript Summary !

azhar bin Shakil
3 min readAug 30, 2021

A reintroduction : JavaScript is a single thread, prototype based programming language that support multiple programming paradigm like Object Oriented programming, functional programming and procedural .

Hence javascript is single thread programming language that work synchronously from its born habit, but it can do some asynchronous job by help of WEB APIs and event loop, which are handled on somewhere else on the browser side .

Example :

setTimeOut(() => console.log("Here I am!"), 1000)
console.log("Hello World!")Output :
Hello World!
Here I am!

So, as the above code example the second statement had not wait 1000 ms for the setTimeOut function to finish his execution , actually the setTimeOut function was handled by WEB APIs either then the call stack directly .

Visual representation of event loop

OPP in Javascript :

OOP in javaScript is not actually identical with c++ or Java . Javascript actually do this kind of task on based on function and prototype. And the class keyword are added to javascript in the ES6 addition , what is just a syntactic sugar .

Example :

class Person{
constructor(_firstName , _lastName){
this.firstName = _firstName;
this.lastName = _lastName;
}

getFullName() {
return this.firstName + " " + this.lastName;
}
}const person1 = new Person('Shakil' , 'ahmed');
console.log(person1.getFullName()) // Shakil ahmed

What it looks like in Javascript Engine (ES5):

function Person(_firstName, _lastName) {
this.firstName = _firstName;
this.lastName = _lastName;
}Person.prototype.getFullName = function() {
return this.firstName + " " + this.lastName;
}const person1 = new Person("Shakil" , "ahmed");
console.log(person1.getFullName()) // Shakil ahmed

Functional programming in JavaScript :

In javascript functions are first class citizen , it mean a function can be passed like a value . That’s the strategy of first class function . those features make javascript able to write code in functional paradigm .

Some Terms of functional Programming :

Pure function : Pure function is a function which does not create any side effect and the result of the function will be same in every time if the arguments remain same .

First class Function : function can be stored in a variable, object, or array , passed as an argument to a function , returned from a function .

Higher Order Function : A higher order function is a function that takes another function as an input, returns a function or does both.

Some Confusing part of JavaScript :

1 . Hositing : In case of variable that declared with var keyword get hoist to the top of function/global scope . variable with let , const will not hosit .

2 . value of this : the value of this refer to the current context/object , the value of this can be change by using bind , call , apply method .

3 . Closure : In a nested function inner function can access to all of its outer function , it’s create closure .

4 . implicit coercion on equality comparison : when we compare something by normal equality operator == , it’s does implicit coercion for the second operand based on the first operand , it will convert the second operand to the data type of first operand .

--

--