DEV Community

Discussion on: 17 Javascript optimization tips to know in 2021 🚀

Collapse
 
ufocoder profile image
Sergey Ivanov • Edited

Code from the article, the second example:

// Longhand
let test: boolean;
if (x > 100) {
    test = true;
} else {
    test = false;
}
// Shorthand
let test = (x > 10) ? true : false;
Enter fullscreen mode Exit fullscreen mode

It could be shorter, like the following:

let test = x > 10;
Enter fullscreen mode Exit fullscreen mode

It could be not easy to read or understand several ternary operators in one and the same statement sometimes

Shorter not means better!