Built in Methods (js)

ref – https://medium.com/@_bengarrison/javascript-es6-exploring-the-new-built-in-methods-b62583b0a8e6

Use Object.assign to assign properties of objects over to your destination object.

Using Object.assign, if there already exist a property/value, and you assign a new property that has the same name over, then the existing property/value gets replaced.

Using Object.assign, we can also do a deep copy of an object.

find and findIndex both find elements for you. It is important to note that find() will return the FIRST element in the Array that satisfies the provided testing function.

Use find to see if ‘d’ exists.

find – looping: a
find – looping: b
find – looping: c
find – looping: c
find – looping: d
res: d

Use findIndex to see if ‘c’ exists.

findIndex – looping: a
findIndex – looping: b
findIndex – looping: c


The reason isNaN() is “broken” is because, ostensibly, type conversions aren’t supposed to happen when testing values.

That is the issue Number.isNaN() is designed to address.

In particular, Number.isNaN() will only attempt to compare a value to NaN if the value is a number-type value.

Any other type will return false, even if they are literally “not a number”, because the type of the value NaN is number.

You can also think of it as anything that’s not NaN when passed to Number.isNaN will return false, while passing NaN into it will yield true.

The ES5 global.isNaN method, in contrast, casts non-numeric values passed to it before evaluating them against NaN, using Number(…)

That produces significantly different results. The example below produces inconsistent results because, unlike Number.isNaN, isNaN casts the value passed to it through Number first.

Number.isNaN will return false immediately if the argument is not a Number

while isNaN first converts the value to a Number

For isNaN():

then it does a NaN === NaN comparison, which results to true.

for Number.isNumber() , as mentioned earlier, we check to see the type of the argument is a Number. If its not a Number, it returns false immediately!

Infinity is actually NOT infinity, it a numeric value that represents Infinity. The actual value is 1.797693134862315E+308. The same for -Infinity, -1.797693134862315E+308