DEV Community

Discussion on: Write beautiful and Elegant Javascript code with short-circuit evaluation.

Collapse
 
akshay9677 profile image
Akshay Kannan

Another interesting short hand expression I would like to add is the following,

Instead of doing this,

if(id === 1 || id === 2 || id === 3 || id === 4){
// 
}
Enter fullscreen mode Exit fullscreen mode

We can do something like this,

if([1,2,3,4].includes(id)){
// 
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
fayomihorace profile image
Horace FAYOMI

Indeed, nice one.