@putout/plugin-apply-nullish-coalescing
🐊Putout plugin add ability to apply nullish coalescing operator (??)
Last updated 3 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/plugin-apply-nullish-coalescing 
SYNC missed versions from official npm registry.

@putout/plugin-apply-nullish-coalescing NPM version

The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. This can be seen as a special case of the logical OR (||) operator, which returns the right-hand side operand if the left operand is any falsy value, not only null or undefined. In other words, if you use || to provide some default value to another variable foo, you may encounter unexpected behaviors if you consider some falsy values as usable (e.g., '' or 0).

(c) MDN

????Putout plugin apply nullish coalescing.

Install

npm i @putout/plugin-apply-nullish-coalescing

Rule

{
    "rules": {
        "apply-nullish-coalescing": "on"
    }
}

❌ Example of incorrect code

result = result || 'hello';
result = typeof result === 'undefined' ? 'hello' : result;

✅ Example of correct code

const result = result ?? 'hello';

License

MIT

Current Tags

  • 2.0.0                                ...           latest (3 years ago)

2 Versions

  • 2.0.0                                ...           3 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (8)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |