DEV Community

Mohit Saud
Mohit Saud

Posted on • Updated on

Importance of double ampersand: logical AND(&&)in JavaScript

  • Saves time and code length.
  • Gets rid of else statement. Basic Example: > if/else statement let x= 2, y =5; if(y>x){ console.log("y is greater than x"); return; }

Using logical AND (&&) as short-circuit property
let x= 2, y =5;
y>x && console.log("y is greater than x");

  • The difference the Short-Circuit property makes that you are able to write the code in few lines and is considered as one of the important features of JavaScript and hence making the JavaScript so powerful.

Top comments (0)