short circuiting in JS with (||,&&,??)

short circuiting: JS stops the evaluating expressions

|| operator in statements:

- let fruit1="" ||"apple"; 
-  console.log(fruit1);
  o/p==>apple;

let fruit2="banana"||"apple"
console.log(fruit2)
     o/p==>banana

So in above example while executing fruit1 javascript got falsy value so it goes to the right of || operator and it will keep on moving right and execute the expressions until it finds the truthy value. if it not gets truthy value even after evaluating last expression it returns the last expression in the statement but in fruit2 code snippet you can see that js stops the evaluating the next expression to || operator becuase it got truthy value so if it gets truthy value it won't care about next expressions in the same statement

&& operator in statements:

javascript stops the evaluating the expressions right to (&&) operator if it gets false in the statement

- let fruit1="" &&"apple"; 
-  console.log(fruit1);
  o/p==>"";

let fruit2="banana"&&"apple"
console.log(fruit2)
     o/p==>apple

??(Nullish coalescing) operator:

javascript stops the evaluating the expressions right to (??) operator if it gets value other than null or undefined in the statement

- let fruit1=null ??"apple"; 
-  console.log(fruit1);
  o/p==>apple;

let fruit2="banana"&&"apple"
console.log(fruit2)
     o/p==>banana

we can observe that while evaluating fruit1 it got null so javascript moves to the right and in fruit 2 javascript is not moving right because it gets the value other than null and undefined so it is giving banana as a value to fruit2 variable