Thought leadership from the most innovative tech companies, all in one place.

12 Important JavaScript Functions Every Web Developer Should Know

Everything you learn here will speed up your development and save your valuable time!

image

In this article, I will show 12 important JavaScript functions for every web developer. Everything you learn here will speed up your development and save your valuable time!

1. Shorten the console log

Are you tired of writing console.log() again and again in your code? This easy script uses bind to shorten the console log to speed up the development process (This can be done with every function). image

2. Merge two arrays into one

If you want to merge two arrays of any size into a single array you can use the concate JavaScript function. image

3. Merge two objects into one

If you working with objects you can merge them together with this simple trick. image

4. Shorten an array

There exist an easy way for web developers to shorten an array. You need to use the length method and pass a number that is smaller than the actual array size. image

5. Shuffle an array

Sometimes you want to randomize the values within an array. To achieve this you can use the Array.sort function with a random compareFunction. image

6. Use isNum to verify a number

With this function, you can check whether a value or variable is a number (int, float, etc) or not. image

7. Use isStr to verify a string

With this function, you can check whether a value or variable is in string format or not. image

8. Use isNull

Often it is useful to check if a result or data is null. image

9. Calculate the performance of a function

If you want to check how long a function runs you can use this approach in your program image

10. Remove duplicates from an array

We often encounter an array with duplicated data in it and use a loop to remove those duplicates. This function can remove duplicates in an easy way without using a loop. image

11. Use logical AND/OR for conditions

Instead of using an if-condition, you can use a logical AND/OR. This can be used within a function for executing commands image or for assigning values image

12. Ternary operator

The ternary operator is just cool. You can avoid bad-looking nested conditional if..elseif..elseif with ternary operators. image

Closing Notes

I hope you find this article helpful! If you also have good JavaScript functions to share feel free to comment here and share them with other developers. Happy JavaScript Coding. Additionally, I created a Gist for accessing the functions which can be found here on my GitHub profile:

👨🏻‍💻🤓🏋️‍🏸🎾🚀 Husband, father of two, geek, lifelong learner, tech lover & software engineer




Continue Learning