Skip to content

Commit

Permalink
docs(contributing): improve code format in checking for undefined o…
Browse files Browse the repository at this point in the history
…r `null`

Co-authored-by: Jan Romann <[email protected]>
  • Loading branch information
relu91 and JKRhb authored Sep 21, 2023
1 parent 31668a0 commit d56b778
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ How then should the contributor deal with nullable variables? For example:
```ts
function(arg1: string | null | undefined) {
// ERROR: not allowed by strict-boolean-expressions
if(!arg) { throw new Error("arg should be defined!))}
if (!arg) { throw new Error("arg should be defined!); }
}
```
Instead of checking for both null and `undefiend` values (`if(arg !== undefined && arg !== null)`) the preferred solution is to use `!=` or `==` operator. Interestingly in JavaScript
with ==, null and undefined are only equal to each other. Example:
Instead of checking for both null and `undefined` values (`if (arg !== undefined && arg !== null)`) the preferred solution is to use `!=` or `==` operator. Interestingly in JavaScript
with `==`, `null` and `undefined` are only equal to each other. Example:
```ts
function(arg1: string | null | undefined) {
// OK
if(arg == null) { throw new Error("arg should be defined!))}
if (arg == null) { throw new Error("arg should be defined!); }
}
```
Expand Down

0 comments on commit d56b778

Please sign in to comment.