Top 10 JavaScript Function Every Developer Should Know in 2021 |

Ashraful Hasan
3 min readMay 5, 2021

JavaScript, a high-level language known as interpreted, prototype-based & dynamic scripting language. Today I would like to share 10 basic concepts of JavaScript with you!

Firstly, Some Important JS Math method:

1) Math.abs( ): This Math. abs( ) function returns the absolute value of a number. The method returns a positive result to any negative or positive number.

//Firstly declare a function number that will give the absolute value.

function number(x, y) { return Math.abs(x ~y) };
console.log(number(1, 5));
// output: 4
console.log(number(5, 3));
// output: 2

2) Math.max( ): Math max( ) function is used to get the max number from a few numbers.

console.log(Math.max( 1, 5, 2, 9));
// output: 9
console.log(Math.max( 1, 55, 2, 88));
// output: 88
console.log(Math.max(-88, -10, -6, -2));
// output: -2

3) Math.min( ) : The Math min( ) function is used to get the min number from a few numbers.

console.log(Math.min(20, 30, 40, 50));
// output: 20
console.log(Math.min(-20, -30, -40, -50));
// output: -50

Now, let me introduce the Array methods of JavaScript. Array refers to a single variable that can contain different elements. It can contain different types of values.

4)Array.length: Array.length is used to find out the length of an array.

let fruits= [ā€œMangoā€, ā€œBananaā€, ā€œAppleā€, ā€œOrangeā€, ā€œWatermalonā€]; console.log(fruits.length)// The output will be 5.

5) Array Destructuring: It is the most effective method for larger code. It will keep you code clean & non-repetative. You might know many wats to add item in an array. But to work with back , array destructuring might be more helpful for you.

const numbers = [1,4,12,13, 17, 15]
const newNumbers = [ā€¦numbers, 19,7] // output: [1,4,12,13, 17, 15,19,7]

6) Array. find: The Array.find() method gives the first value that matches the condition.

let numbers = [ 1, 2, 3, 4, 5];
const search = numbers.find(number => number > 3);
console.log(search); // output: 4

7) Array.map( ): Array.map() method loops through out all element of the array and returns with a new array. This method can be used to manage data from database or some data stored in Backend api.

const users = [ā€˜Leonalā€™, ā€˜Johnā€™, ā€˜Kerryā€™]

users.map(user => users+ā€™ Messiā€™)

// output: [ ā€œLeonal Messiā€, ā€œJohn Messiā€, ā€œKerry Messiā€ ]

8) Array.filter(): If you are working with data, many times you will need to filter it. Array.filter method do the task for you.

const numbers = [1,2,3,4,5,6,7,8,9]
const odd = numbers.filter(num => num % 2 === !0)
console.log(odd) // [1,3,5,7,9]

9) Array.shift( ) : This method removes an element from the first index of the array.

let fruits= [ā€œMangoā€, ā€œBananaā€, ā€œAppleā€, ā€œOrangeā€, ā€œWatermalonā€]; fruits.shift();
console.log(foods); // output:
[ā€œBananaā€, ā€œAppleā€, ā€œOrangeā€, ā€œWatermalonā€]

10) Array.unshift: This method inserts an element in the first index of the array.

let fruits= [ā€œMangoā€, ā€œBananaā€, ā€œAppleā€, ā€œOrangeā€, ā€œWatermalonā€]; fruits.unshift(ā€œNutsā€);
console.log(foods);//
[ā€œNutsā€,ā€œMangoā€, ā€œBananaā€, ā€œAppleā€, ā€œOrangeā€, ā€œWatermalonā€]

Thats all for today & Thanks for reading! My name is Ashraful Hasan. You can call me simply Ashraful! šŸ˜

Follow me on Github & LinkedIn if youā€™d like to keep on touch with me. Have fun with coding & never lose hope.

--

--