DEV Community

Discussion on: 9 Beginner Friendly Tricks every JavaScript Dev Should know

Collapse
 
prakhart111 profile image
Prakhar Tandon

There are a lot of cool things you can do with bitwise operators.
My fav is this - A function to check if a given positive integer is a power of 2

function isPowerofTwo(num){
     if( num & (num-1) == 0 ) return true;
return false;
}
Enter fullscreen mode Exit fullscreen mode

And you can also include arrow functions, they makes things better.

const fun = () =>  console.log("Namaste") 
Enter fullscreen mode Exit fullscreen mode