You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/05/15 17:18:14 UTC

[GitHub] [arrow] domoritz opened a new pull request #10339: ARROW-12799: [JS] Use Nullish Coalescing Operator (??) For Defaults

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:
users@infra.apache.org



[GitHub] [arrow] domoritz closed pull request #10339: ARROW-12799: [JS] Use Nullish Coalescing Operator (??) For Defaults

Posted by GitBox <gi...@apache.org>.
domoritz closed pull request #10339:
URL: https://github.com/apache/arrow/pull/10339


   


-- 
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:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #10339: ARROW-12799: [JS] Use Nullish Coalescing Operator (??) For Defaults

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #10339:
URL: https://github.com/apache/arrow/pull/10339#issuecomment-841696000


   https://issues.apache.org/jira/browse/ARROW-12799


-- 
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:
users@infra.apache.org



[GitHub] [arrow] domoritz closed pull request #10339: ARROW-12799: [JS] Use Nullish Coalescing Operator (??) For Defaults

Posted by GitBox <gi...@apache.org>.
domoritz closed pull request #10339:
URL: https://github.com/apache/arrow/pull/10339


   


-- 
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:
users@infra.apache.org