# Operators: differences from JS

| Rook              | JS          | Note                                                      |
| ----------------- | ----------- | --------------------------------------------------------- |
| `a == b`          | `a === b`   | the language has no loose comparison                      |
| `a != b`          | `a !== b`   |                                                           |
| `x == null`       | `x == null` | stays loose: catches both `null` and `undefined`          |
| `a = b`, `a += b` | the same    | only as a statement: `f(a = 1)`, `a = b = c` are errors   |
| `i++`, `i--`      | the same    | only as a statement: `a = i++` is an error; no `++i`      |
| `&&`, `\|\|`, `!` | the same    | only for `bool`; a default value is written with `??`     |
| `a + b`           | the same    | numbers or strings; `"a" + 1` is an error, use a template |
| `x as T`          | `x`         | the types must be related, see below                      |
| `delete obj.key`  | the same    | only as a statement, see below                            |

The rest is as in JS: arithmetic, comparisons, bitwise operations, `**`, `??`, `?.`, `? :`,
`typeof`, `instanceof`, `new`, spread `...`, indexing `xs[i]`.

The language has no `var`, `function`, `===`, `while`, `do...while`, `for...in`, `with` or comma
operator.

- **`value as Type`** sees a value as another type, as in TypeScript, and leaves nothing in JS. The
  types must be related, one assignable to the other: `element as HTMLInputElement` and
  `JSON.parse(text) as Config` pass, `count as string` is an error. `as` binds like a comparison:
  `a + b as number > c` is `((a + b) as number) > c`. A variable named `as` is still a name.
- **`delete obj.key`** removes a key of a map (`{ [string]: T }`), a field of type `?T`, or a field
  of an `any`; a required field cannot be deleted, and an array needs `splice`. It is a statement,
  also in handlers, and in a component it updates what reads the object. `delete` is a keyword only
  at the start of a statement.

Only a function call or `new` can be a statement on its own, as in Go: a line `a + b` or
`user.name` by itself is an error. This catches typos and a line break before a binary operator:

```go
const total = price
    + tax              // error: there is already a ; after price, and "+ tax" does nothing
```

