Anyone can publish on Medium per our Policies, but we don’t fact-check every story. For more info about the coronavirus, see cdc.gov.

JavaScript Shorthand Coding Techniques

SaravananVijayamuthu
Jun 22 · 3 min read

✨ The Ternary Operator ✨

Longhand 👉

Shorthand 🤏


✨ Short-circuit ✨

Longhand 👉

Shorthand 🤏

When assigning a variable value to another variable, you may want to ensure that the source variable is not null or empty. You can either write a long if-else statement with multiple conditionals, or use short-circuit evaluation.


✨ Declaring Variables Shorthand ✨

Longhand 👉

Shorthand 🤏

It’s a good practice to declare your variable assignments at the beginning of your functions. This shorthand method can save time and space when you are declaring multiple variables at the same time.


✨ If Presence Shorthand ✨

Longhand 👉

Shorthand 🤏


✨ JavaScript for Loop Shorthand ✨

Longhand 👉

Shorthand 🤏

If you wanted to access the index, do:


✨ Short-circuit ✨

Longhand 👉

Shorthand 🤏


✨ Decimal Based Exponents ✨

Longhand 👉

Shorthand 🤏


✨ Object Property Shorthand ✨

Longhand 👉

Shorthand 🤏

Defining objects in JS makes work much easier. ES6 provides an even easier way of assigning properties to objects. If the variable name is the same as the object key, you can take advantage of shorthand notation.


Like this article? Follow @saravanan.raghul on Instagram

Frontend Weekly

It's really hard to keep up with all the front-end…

SaravananVijayamuthu

Written by

Ambivert. Webdev. Communicator. Internet guru. Coffee enthusiast. cynophile.

Frontend Weekly

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co

SaravananVijayamuthu

Written by

Ambivert. Webdev. Communicator. Internet guru. Coffee enthusiast. cynophile.

Frontend Weekly

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store