Important JavaScript Shorthands to know 🚀🔥

arjuncodess

Arjun Vijay Prakash

Posted on May 25, 2022

Important JavaScript Shorthands to know 🚀🔥

1) The Ternary Operator

Longhand-

const x = 20;
let answer;
if (x > 10) {
    answer = "greater than 10";
} else {
    answer =  "less than 10";
}
Enter fullscreen mode Exit fullscreen mode

Shorthand

const answer = x > 10 ? "greater than 10" : "less than 10";
Enter fullscreen mode Exit fullscreen mode

2) Declaring Variables Shorthand

Longhand-

let x;
let y;
let z = 3;
Enter fullscreen mode Exit fullscreen mode

Shorthand

let x, y, z=3;
Enter fullscreen mode Exit fullscreen mode

3) If True Presence Shorthand

Longhand-

if (likeJavaScript === true)
Enter fullscreen mode Exit fullscreen mode

Shorthand

if (likeJavaScript)
Enter fullscreen mode Exit fullscreen mode

4) If Not True Presence Shorthand

Longhand-

if (!likeJavaScript === true)
Enter fullscreen mode Exit fullscreen mode

Shorthand

if (!likeJavaScript)
Enter fullscreen mode Exit fullscreen mode

5) Arrow Function Shorthand

Longhand-

function doAnything(){}
Enter fullscreen mode Exit fullscreen mode

Shorthand

let doAnything = () => {}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
arjuncodess
Arjun Vijay Prakash

Posted on May 25, 2022

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

Sign up to receive the latest update from our blog.

Related