This content originally appeared on DEV Community and was authored by Mohit Saud
- 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.
This content originally appeared on DEV Community and was authored by Mohit Saud
Mohit Saud | Sciencx (2021-11-09T04:36:20+00:00) Importance of double ampersand: logical AND(&&)in JavaScript. Retrieved from https://www.scien.cx/2021/11/09/importance-of-double-ampersand-logical-andin-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.