JavaScript Article 2

143_Borshon Saha
3 min readMay 6, 2021

1. typeof() expression:
typeof() is a javascript keyword which is used to
know the type of any variable. Mainly it returns
the type of any variable. This is most useful because
it is easy to use.
Example:

console.log(typeof(20)); -> “number”
console.log(typeof(“hi there”)); -> “string”
console.log(typeof(undefined)); -> “undefined”

2. Call Stack:
Call stack is a mechanism which records where in
the program we are. The call stack works based on
the LIFO(Last in first out) principle.
When javascript engine execute a function it pushes
into top of the call stack.
If it a function calls another function again it
pushes top of the call stack.
when current function execution is completed it will
popped out from the top of the call stack.
When call stack is empty program will stop.

3. Asynchronous Callback:
Asynchronous callbacks are special functions that
are specified when we calling a function which will
start executing in the background. When background
code execution completed, it calls the callback
function to let us know the work is done.

4. Event Loop:
Event loop is a powerful mechanism of javascript
asynchronous programming.
JavaScript can do one thing at a time. We cannot
execute other codes while running a code.
JavaScript works on a single thread. But by the
helping of event loop we can achieve multi-threading.
Based on event loop javascript concurrency model
works.

5. Coding Style:
Writing code is an art. There are some rules
that should apply while we are writing codes.

• Space between parameters.
function power(base, pow){}

• Space after for, if, while.
for (let i = 0; i < n; i++){}

• Space around nested calling.
foo( bar(a, b) );

• else without a line break
if (a < b){

}else {

}

• Lines should not be very long.

6. try & catch statement:
try and catch statement mainly used for handling
the error.
When our code start executing, there might be a
code snippet where error might be occurred an
error. We simply write these on try block.
If error occurred then it will handle by catch
block. So user will not face any exception.
Syntax:

try{
//…
}catch(error){
//…
}

7. Caching:
Caching is a mechanism by which browsers can access
data without communicating with server.
Client caching is the most efficient type of caching.
When a client requests a file to the server it simply
stores into the application media.
Server caching is a technique by which contents are
temporarily saved in the server side.

8. Var Declarations and Hoisting:
Variable must be declared within scope or globally.
Within scope we can not access it from outside of
the scope.
But if it is declared globally it can be access
anywhere.
Example:

let a=10;
function add(){
let b=20;
let sum = a+b; // a can be access here
}

function display(){
console.log(sum); // sum can not be access here
}

a declared globally, so it is accessible.
But sum is outside the scope.

9. Arrow Functions:
Arrow functions are the most simpler and easier
way to write function which is introduced in ES6.

Normal Function:
let x = function(x, y) {
return x * y;
}

Arrow Function:
const x = (x, y) => x * y;

10. Spread Operators:
Spread operators are special types of operators
which is introduced in ES6. This is mostly
used for make copies of objects. Which is more
easier.
Example:

let n1 = [10, 20, 30];
let n2 = [40, 50, 60];

let all = […n1, …n2];
console.log(all); -> [ 10, 20, 30, 40, 50, 60 ]

--

--