#+= in an array

3 messages · Page 1 of 1 (latest)

analog owl
dim pathBOT
#

@analog owl Here's a shortened URL of your playground link! You can remove the full link from your message.

engardiun#0

Preview:```ts
const array = [1, 2, null]

const index = 5

array[index] ||= 0
array[index] += 3

let indexB = 5

array[indexB] ||= 0
array[indexB] += 3```

main rover
#

In the case of const index = 5, TS knows that it cannot change, and array[index] ||= 0 ensures that element cannot be null, so the latter += 3 is allowed.