# Precedence

OSL evaluates expressions using a fixed operator precedence hierarchy. Operators with **higher precedence bind tighter** and are evaluated before lower-precedence operators. Operators at the same precedence level are evaluated **left-to-right**, unless otherwise stated.

Parentheses `(...)` may always be used to override precedence.

#### Precedence Table

<table data-header-hidden><thead><tr><th width="136.1881103515625"></th><th></th><th></th></tr></thead><tbody><tr><td>Level</td><td>Operators</td><td>Description</td></tr><tr><td>1</td><td><code>()</code></td><td>Grouping / explicit precedence override</td></tr><tr><td>2</td><td><code>+</code> <code>-</code> <code>/</code> <code>*</code> <code>^</code> <code>%</code> <code>??</code> <code>|></code></td><td>Operators</td></tr><tr><td>3</td><td><code>==</code> <code>!=</code> <code>&#x3C;</code> <code>></code> <code>&#x3C;=</code> <code>>=</code></td><td>Comparisons</td></tr><tr><td>4</td><td><code>bool ? val1 val2</code></td><td>Ternary operator</td></tr><tr><td>5</td><td><code>|</code> <code>&#x26;</code> <code>>></code> <code>&#x3C;&#x3C;</code> <code>>>></code> <code>^^</code> <code>&#x3C;&#x3C;&#x3C;</code> </td><td>Bitwise operators</td></tr><tr><td>6</td><td>and, or, nor, nand, xor, xand</td><td>Increment (prefix or postfix, context-dependent)</td></tr><tr><td>7</td><td><a data-mention href="/pages/TEnU4ykHHV5gEg8l1F9L">/pages/TEnU4ykHHV5gEg8l1F9L</a></td><td>Lambda and inline functions</td></tr></tbody></table>

This table is in order of what gets evaluated first, within these groups its the left most operator that takes precedence.

```javascript
// Think of:
log 1 + 1 * 4

// As:
log (1 + 1) * 4
```

Because operators come first in the table, they are evaluated before comparisons and so you can do things like this:

```javascript
// this logs `false`
log 1 + 1 == 5 * 4

// the code above is functionally equivalent to
log (1 + 1) == (5 * 4)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://osl.mistium.com/operators/precedence.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
