6 Javascript Tips I Know !!
1 min readMay 3, 2021

1 — undefined
, null
, 0, false
, NaN
, ''
(empty string) are all falsy.
2 — Get a random item from an array
var items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119];
var randomItem = items[Math.floor(Math.random() * items.length)];
3 — Get a random number in a specific range
var numbersArray = [] , max = 100;
for( var i=1; numbersArray.push(i++) < max;); // numbers = [1,2,3 ... 100]
4 — Empty an array
var myArray = [12 , 222 , 1000 ];
myArray.length = 0; // myArray will be equal to [].
5 — use ===
instead of ==
6 — use destructuring
The technique of breaking down the array elements and object properties as variables called, destructuring. Let us see it with few examples,let emojis = ['🔥', '⏲️', '🏆', '🍉'];let [fire, clock, , watermelon] = emojis;console.log(fire, clock, watermelon);Output: