Top JavaScript Tricks and Tips
In this article, we are going to look at some helpful JavaScript tricks.
When you write your code, you may feel that there was a better way of doing this. So let me show you some interesting tricks you might use in your code and make your code shorter and more straightforward.
We are going to understand the fundamentals of these tricks and their use case. Let me start with a simple one that you probably know. Or not.
Swap elements of an array
Lots of array operations require the swapping of elements, for example, sorting. You would need to write a small utility function and The typical algorithm requires a temp variable for swapping. But ever since, I have learned this trick. It’s awe-inspiring. During a couple of coding interviews, I used this trick to impress the interviewer, and it has worked well. Some of them go, What is that syntax?
We will use destructing to achieve that. Destructing was introduced in the ES6 version of JavaScript.