Javascript and React learnings of some past months.

1.) _isMounted

I recently found out about this when one of my colleague used this in his code and then I found out that in order to check whether our React component is mounted or not we can use this._isMounted in our lifecycle methods and it will return the boolean according to whether the component is mounted or not.

2.) lastIndexOf in JS array

It was when i was trying to solve a fairly simple problem statement i.e In an array we have to find the duplicate item, for example in array [3,4,3,2,1] is 3 repeated and we have to console the duplicate item. so in order to achieve this, I used lastIndexOf array method. In most common scenarios , I don’t think it's used too much. But this is solution i could think and it made problem fairly easy for me.

let array = [3,4,5,6,4,3] 

let duplicates = array.filter((item)=>{ return array.indexOf(item) !== array.lastIndexOf(item)})

It might be a longer solution but i found the use of lastIndexOf interesting.

3.) CSS name we give to components isn't the same name after compilation while using SASS.

When we use SCSS and give some class to particular div or element i used to believe that after we inspect the element the class applied is same but it's not the case while using SASS there is always some extra string that's appended to class names in the end so while inspecting the name that you will see will be

classNameGivensomeString

One more thing that i learned was how to close the dropdown when we click outside it's div. But I will be writing a separate blog with demo for that.