Comparison operations in javascript
Javascript / June 1, 2018

Javascript provides three types of comparison Abstract equality (Achieved using ===) Strict equality (Acheived using ==)

In the above example a is a number and b is a string .If we compare strictly with === the result would be false and if we compare loosely with operator == the result would be true.The abstract equality operator returns true irrespective of the type.Loose equality compares two values for equality, after converting both values to a common type. Object.is determines whether two values are same value.

 

Array reduce functions in Javascript
Javascript / June 1, 2018

The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.Reduce function makes it to a single value.

Here we can see reduce always accepts a call back function. The variable a  is called the accumulator in which the return value is stored The variable b represents each variable inside the array.Thus what reduce does is that it runs a function on each values inside the array. The return value of the function is stored in an accumulator (result/total). Now we take a look at how to calculate the sum of squares of all the values present inside the array.So that you get a better understanding of what happens inside the reduce function.This time we define the function seperately.

  The above returns sum of squares of all values inside the array.

Array map functions in Javascript
Javascript / June 1, 2018

Conside a Javascrpt Array of numbers.We need to make an array which contains squares of all these numbers.What we can do to achieve this is using a for loop.

For doing these Javascript has another function called MAP function on array.Using the map function the above result can be achieved in the following way

Array Map on Array of objects in Javascript

 

Share this page in social media platforms