Some JavaScript Story

01. Coding Style

Coding Style not mandatory to apply for your code. But coding style is a good practice and your code clean and readable to apply code style.

Code style applies some rules:

  1. A space between parameters,
  2. Curly brackets { on the same line, after space,
  3. A use semicolon mandatory for style,
  4. A space after for/if/while,
  5. A space between arguments etc.

O2. Comments

We know comments code structure single line or multi-line. we normally use the describe how and why code works.

when using comments:

  1. Architecture, high level-view,
  2. Function usages,
  3. Important solutions etc.

when not use comments :

  1. How code works and what it das.

03. Var Declarations and Hositings

If we var declare to function top/outside of a function, that's the global scope /functional scope. Functionals cope variable use any position out of function or inside function.


function value1(condition) {

if (condition) {
var value = “blue”;

return value;
} else {

// value exists here with a value of undefined

return null;

// value exists here with a value of undefined

04. Block Level Declarations.

Block-level declare to system/ way, 1.Inside of a function, 2.Inside of a block.

Let Declarations:

let declare system/syntax same as var system/syntax. basically, replace var with let to declare a variable, but the limit is only the current code block.


function value1(condition) {

if (condition) {
let value = “blue”;

// other code

return value;
} else {

// value doesn’t exist here

return null;

// value doesn’t exist here

Const Declarations:

const variables defined with const declarations syntax. variables declared using const their value can not be changed.


value constant
const terms = 30;

Syntax error: missing initialization
const name;

05. Block Bindings in Loops

This is one area where developers most want block-level scoping of variables is with loops, where the counter variable is meant to be used only inside the loop. For for this we have to use let not var, cause var is being hoisted.


for (var i = 0; i < 10; i++) {

i is still accessible here

06. Functions in Loops

The behavior of var made creating functions inside of loops problem because the loop variables are accessible from outside the scope of the loop.

var fun = [];

for (var i = 0; i < 10; i++) {
fun.push(function() { console.log(i); });

funcs.forEach(function(func) {
func(); outputs the number “10” ten times

07. Global Block Bindings

let and const are different from var is in their global scope behavior.

when var is used in the global scope, it creates a new global variable, which is a property of the global object. That means you can accidentally overwrite an existing global using var.


var RegExp = “Raju!”;


var abc = “Biswas”;


08. Arrow Function Expression

An arrow functions expression a compact alternative traditional function. but is limited can not be used in all situations. can not be used, constructor. Can not be used yield body. Not suitable for the call, apply bind method.

09. try……catch

try…catch is an error handling method.

try…catch syntax

try {

// code…


catch (err) {

// error handling


first code try{…} is execute if code no error catch ignore and if code error try ignore and catch in and showing error.

10. Spread Operator

spread operator array element and one more element adding create a new array easily also spread operator object element and another element adding e all element create a new object..and change original array or object easily.

Example: Array

function sum(x, y, z) {
return x + y + z;

const numbers = [1, 2, 3];

output: 6

Example: OBJECT.

let p1 = {

name: “Raju”,

age: 25


let p2 = {

country: “Ban”,

occupation: “student”


let p = {…p1, …p2}



name: ‘Raju’,

age: 25,

country: ‘Ban’,

occupation: ‘student’



I'm a Front-end Developer and Familiar with work's Backend. I enjoy working with Team as a leader or member.I Always learning New technology. I enjoy it.