10 most important functions that every Javascript developer use in daily life

Hrridoy V2
2 min readNov 2, 2020

String.prototype.slice():

To extract a section from a string slice() method is used. It returns a new string after extract a section form a string, but doesn’t change primary string. The method need two value as a index. First value is starting index, and second index is ending index. The new string after slice will be section of primary string from starting index to ending index. The value also may negative or positive. If index value is positive then count start from left side of primary string, else if value is negative then count start from right side of primary string.

String.prototype.concate() :

In order to merge two or more string, then concate() function is required. It returns new string after merge, but doesn’t change primary strings.

String.prototype.trim():

The trime() method delete whitespaces from both side of string. Whitespace means all the whitespace characters such as space, tab, no-break space etc.

Array.prototype.spilice():

This method works for extract item, deleted item and add item insteadly. This method changes the primary Array. It contains three value, first is starting index for extract, second is count number to delete item, third for items that want to add to the Array.

Math.random():

To make random number Math.randon() method is required for that. It returns a floating-point, pseudo-random number in the range . To get a random number between two values. The method will be Math.random() * (max-min) + min.

Math.round():

To get nearest integer value from a fractional number Math.round() is used for that. If the fractional portion of the number is lower than 0.5 the absolute value will be the previous integer value. else if , fractional portion of the number is greater than 0.5 , the value will be the higher integer.

Math.abs():

Math.abs() function always returns absolute value. Absolute value contains only positive value. So whatever number we set for Math.abs() it always returns positive number.

Array.prototype.sort():

To sorts an array, sort() is used. The default order is ascending. So, get a ascending order from the array, after sorting reverse() method should be applied.

Array.prototype.find():

Finding a value from array according to a function. find() method is used for that. It returns the first element that satisfied the function.

Array.prototype.filter():

The filter() method returns a new array with all elements that satisfied the provided function. Difference from find() is that, find() method returns first element only, but filter() method returns all elements that satisfied the provided function.

--

--