> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ns.rocks/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript And TypeScript

> Run JavaScript and TypeScript cells with the code interpreter kernels.

The standard `code-interpreter` template includes JavaScript and TypeScript
kernels backed by Node.js tooling.

<CodeGroup>
  ```python Python SDK theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  result = machine.run_code("""
  const values = [1, 2, 3]
  console.log(values.reduce((total, value) => total + value, 0))
  """, language="javascript")

  print("".join(result.logs.stdout))
  ```

  ```typescript TypeScript SDK theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  const result = await machine.code.run(`
  const values = [1, 2, 3]
  console.log(values.reduce((total, value) => total + value, 0))
  `, { language: "javascript" });

  console.log(result.logs.stdout.join(""));
  ```

  ```bash CLI theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  nullspace machine code run mch_123 "const values = [1, 2, 3]
  console.log(values.reduce((total, value) => total + value, 0))" --language javascript
  ```

  ```bash HTTP API theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  # returns a Server-Sent Events stream of JSON events
  curl -N -X POST "${NULLSPACE_API_URL}/v1/machines/mch_123/code/execute" \
    -H "Authorization: Bearer ${NULLSPACE_API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{"code": "const values = [1, 2, 3]\nconsole.log(values.reduce((total, value) => total + value, 0))", "language": "javascript"}'
  ```
</CodeGroup>

Use TypeScript when you want typed snippets:

<CodeGroup>
  ```python Python SDK theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  result = machine.run_code("""
  const value: number = 42
  console.log(value)
  """, language="typescript")
  ```

  ```typescript TypeScript SDK theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  const result = await machine.code.run(`
  const value: number = 42
  console.log(value)
  `, { language: "typescript" });
  ```

  ```bash CLI theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  nullspace machine code run mch_123 "const value: number = 42
  console.log(value)" --language typescript
  ```

  ```bash HTTP API theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  # returns a Server-Sent Events stream of JSON events
  curl -N -X POST "${NULLSPACE_API_URL}/v1/machines/mch_123/code/execute" \
    -H "Authorization: Bearer ${NULLSPACE_API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{"code": "const value: number = 42\nconsole.log(value)", "language": "typescript"}'
  ```
</CodeGroup>

Create a context when cells need to share variables, imports, or working
directory state.

## Related

* [Supported languages](./languages-overview)
* [Code contexts](./contexts)
