Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions files/en-us/web/javascript/reference/statements/using/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ In both cases, when the scope exits, `resource2` is disposed before `resource1`.

### Optional `using`

`using` allows the variable to have value `null` or `undefined`, so the resource can be optionally present. This means you don't have to do this:
`using` allows the variable to have a value of `null` or `undefined`, so the resource can be optionally present. This means that, for example, if you are checking the availability of a resource of some kind:

```js
function acquireResource() {
Expand All @@ -175,7 +175,11 @@ function acquireResource() {
}
return new Resource();
}
```

You don't have to do this:

```js example-bad
const maybeResource = acquireResource();

if (maybeResource) {
Expand All @@ -186,9 +190,9 @@ if (maybeResource) {
}
```

But can do this:
And can instead do this:

```js
```js example-good
using resource = acquireResource();
console.log(resource?.getValue());
```
Expand Down