Awesome 5 javascript Shorthands

iftekhs

iFTekhar

Posted on March 19, 2021

Awesome 5 javascript Shorthands

In this blog, I have shared 5 awesome shorthand tricks to make a developer's life faster!

1) Setting the variables values

Normally you would define a variable then say x = value and if you have lots of variables (obviously) then it could take more time.

So you can simply define variables inside a set of square brackets then put the values on another set of square brackets like this.

Alt Text

2) Using Double Bitwise NOT operator instead of Math.floor()

Well you might have surely used Math.floor() to get rid of the decimal points but there is an easier way of doing the same operation using the Double Bitwise NOT operator it performs the same operation much faster.

Alt Text

3) For loop short hand

Instead of using a for-loop like the way we usually use you can just simply do this.

image

4) The logical AND operator

Suppose you want to call a function if one condition or statement is true or false. you would say if(something) then call function but instead of doing that there is a really better way of doing it which is to say something && callFunction() which means if the something is true then that function is going to be called.

Alt Text

5) Turning array into object

You might do a lot of things in order to just turn an array into an object. but the simplest way I think is to use the so-called spread operator or the ... operator

Alt Text

That was it! Thank you for reading my blog hope this makes your developing life fast and let me know if you like this little blog of mine. Thank you so much for reading this!🙂

💖 💪 🙅 🚩
iftekhs
iFTekhar

Posted on March 19, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related