domoritz opened a new pull request #10339:
URL: https://github.com/apache/arrow/pull/10339


   **The nullish coalescing operator (`??`) returns its right side when its 
left side is nullish** (`null` or `undefined`), and its left side otherwise.
   For example, `const x = a ?? b` would set `x` to `a` if `a` has a value, and 
to `b` if `a` is `null` or `undefined`.
   
   The nullish coalescing operator is very useful to **provide default values 
when a value or an expression is nullish**.
   Before its introduction in ES2020, this default value pattern was often 
expressed using the conditional operator.
   
   This refactoring simplifies conditional (ternary) checks to nullish 
coalescing operator expressions:
   
   * `a == null ? x : a` becomes `a ?? x`
   * `a != null ? a : x` becomes `a ?? x`
   * `a === null || a === undefined ? x : a` becomes `a ?? x`
   * `a !== null && a !== undefined ? a : x` becomes `a ?? x`
   * `f(1) != null ? f(1) : x` becomes `f(1) ?? x`
   * etc.
   
   Learn More: [Nullish coalescing operator 
(MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator)
   
   When two similar-looking function calls have a side effect, this refactoring 
can change the behavior of the code.
   
   For example, the refactoring changes:
   
   ```javascript
   let a = f(1) === null || f(1) === undefined ? 'default' : f(1);
   ```
   
   into
   
   ```javascript
   let a = f(1) ?? 'default';
   ```
   
   If `f(1)` has a side effect, it would have been called one, two or three 
times before the refactoring, and once after the refactoring.
   This means that the side effect would have been called a different number of 
times, potentially changing the behavior.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to