10 thing I learned about Javascript

Noman
3 min readMar 14, 2022

1.Variable declaration: In older versions of EcmaScript we used var for all variable declaration. As var hoisted globally and it is not block scope sometimes developers get some unusual and unexpected errors. In EcmaScript it is solved now we have two new ways to declare a variable , let and const .const uses those variables whose value is unchangeable and let uses those variables whose value is changeable and changed in the program.

As let and const is block scope variable developers never get unexpected errors .

2.Js conditional Operators: Among the operators of Javascript the most usable and important operators are >, <, ===, !==, >=. <= , let’s get an overview about those operators.

  • Greater than(>):It is used to compare two things. The 1st thing is greater than the second thing .
  • Less than(<): It is used to compare two things. The 1st thing is Less than the second thing .
  • Equal(===): As we were using double equal but triple equal has its another advantage . the double equal chaques only the things value but triple equal chaques things value and type also.
  • Not Equal(!++): We are more equal(!=)l that is older version es6 introduced this sign that chaques the comparing thing value and type that is more accurate than older version.
  • Greater than Equal(>=): It chaques things that are either equal or Greater than from another.
  • Less than Equal(<=): It chaques things that are either equal or Less than from another.

3.Conditional statement (if-else): When we have two ways of true or false we use if-else condition.It does yes or no. we can also give it more condition using else-if.

4.Using loop in Object and Array:When we want to loop through an array or object we can use for loop . But when we loop through an array we should use for-of loop and when we loop through an object we should use for in.

Because for in give elements randomly so if effective to object but if we want to use for-in in an array it should return undefined.

5.Difference and Usage of normal Function and Arrow Function:In ES6 we are introduced to arrow function. Arrow function is block scoped and it is simple to use. The differences between arrow function and normal function is that the arrow function cannot be hoisted globally but normal function done. An arrow function cannot hold it’s .this method.

6.Destructuring Array and Object: In the usaucase we should destructure an array or object.array can be destructured by array.kay and array.value.In the below i give a code to know easily.

const array=[2,3]

let [a,b]=array;

console.log(a)//output:2.

console.log(b)//output:3.

const obj={a:3,b:4};

const{a,b}=obj;

console.log(a)//output:3.

console.log(b)//output:4

There are more way to destructuring array and object, Please visit MDN document or another document to know those

7.More about Template string: In es6 we are introduced to many powerful things of javascript, one of them is template string. Using template string by backtic (``). In those backticks we can use any valid javascript expression by this code (${}).

8.Spread operator: In code sometimes we need to duplicate an array but the problem is if the main array was changed the duplicated array is changed it is terrifying. For this problem es6 introduces us to the spread operator (..) by using this operator we can copy and use an array though the main array changed by array methods.

9.Local storage and Session storage:

Difference between Local Storage and Session Storage:

  1. Session storage data will erase when the browser or tab closes. Local storage data never will be erased until manually or programmably erased.
  2. Session storage has more than 5 mb data capacity when Local storage has the highest 5 mb data capacity.
  3. Local storage is global; it can be accessible from any tab of the browser when Session storage is different from tab to tab.

10.Usage of forEach and map: map and forEach those are used to loop through and get one by one element from an array. But when we don’t need to return something we use forEach and we have to return something we should use map. Because forEach didn’t return anything but map did.

--

--