# Introduction

AxScript is built on top of the JavaScript engine from Qt's JSEngine framework. AxScript shares the same syntax as JavaScript:

* variable definition and basic operations

```javascript
let a = 5 + 23;  // let - block environment
if (a > 12) {
    var b = 12;  // var - global (func) environment
}
ax.log(b)        // print: 12
```

* Basic String operations

```javascript
// Create
let str1 = "Hello";
let str2 = 'World';
let str3 = `Hello ${str2}`;     // Hello World

// Operations
"Hello" + " " + "World"	        // "Hello World"
"Hello".length	                // 5
"Hello"[1]	                // "e"
"Hello".includes("ell")	        // true
"Hello".replace("llo", "y")	// "Hey"
"a,b,c".split(",")	        // ["a", "b", "c"]
"Hello".slice(1, 3)	        // "el"
"Hello".toUpperCase()	        // "HELLO"

// ... And other string JS operations
```

* Basic Array operations

```javascript
// Create
let arr1 = [1, 2, 3];
let arr2 = new Array(1, 2, 3);
let arr3 = ["a", 42, true, { name: "John" }];

// Operations
arr1.length                 // 3
arr1[1]	                    // 20
arr1.push(10)	            // 4 (arr1: [1, 2, 3, 10])
arr1.pop()                  // 3 (arr1: [1, 2])
arr1.unshift(10)            // 4 [10, 1, 2, 3]
arr1.shift()                // 1 (arr1: [2, 3])
arr1.concat([4, 5])         // [1, 2, 3, 4, 5]
arr1.indexOf(2)             // 1
arr1.includes(2)	    // true
arr1.filter(x => x > 1)     // [2, 3]
arr1.map(x => x * 2)	    // [2, 4, 6]
[3, 1, 2].sort()	    // [1, 2, 3]
[1, 2, 3].reverse()	    // [3, 2, 1]
[1, 2, 3, 4].slice(1, 3)    // [2, 3]
arr1.splice(1, 1, 99)       // [2] (arr1: [1, 99, 3])

// ... And other array JS operations
```

* Basic Map/Object operations

```javascript
// Create
let obj1 = { name: "Alice", age: 25 };
let obj2 = new Object();
obj2.key = "value";

// Operations
obj1.name	                         // "Alice"
obj1["name"]	                         // "Alice"
obj1.city = "Tokyo"	                 // { name: "Alice", age: 25, city: "Tokyo" }
delete obj1.age	                         // { name: "Alice" }
"name" in obj1	                         // true
Object.keys(obj1)	                 // ["name", "age"]
Object.values(obj1)	                 // ["Alice", 25]
let newObj = { ...obj1 }	         // copy of
Object.assign({}, obj1, { city: "Tokyo" })  // {name: "Alice", age: 25, city: "Tokyo"}

// ... And other object JS operations
```

* Function Declaration

```java
// Classic
function greet(name) {
  return `Hello, ${name}!`;
}
ax.log(greet("Alice")); // "Hello, Alice!"


// Expression
const greet = function(name) {
  return `Hello, ${name}!`;
};
ax.log(greet("Bob")); // "Hello, Bob!"


// Arrow
const greet = (name) => `Hello, ${name}!`;
ax.log(greet("Charlie")); // "Hello, Charlie!"
```

* Functions and parameters

```javascript
// Default
function greet(name = "Guest") {
  return `Hello, ${name}!`;
}
ax.log(greet()); // "Hello, Guest!"


// Undefined number of arguments
function greet(greeting, ...names) {
  return `${greeting}, ${names.join(", ")}!`;
}
ax.log(greet("Hello", "Alice", "Bob", "Charlie"));  // "Hello, Alice, Bob, Charlie!"


// Arguments via object
function greet({ name, age }) {
  return `${name} is ${age} years old.`;
}
ax.log(greet({ name: "Alice", age: 25 })); // "Alice is 25 years old."

```

* You can interrupt the execution of a function or script and pass the error to the underlying client using `throw`.

```javascript
throw new Error("error text");
```

* Regular Expressions

```javascript
/\d+/.test("123");                                // true
"abcdef".match(/abc/);                            // abc
"hello123".replace(/\d+/, "");                    // hello
"one, two, three".split(/\s*,\s*/);               // ["one", "two", "three"]

let regex = /hello/gi;
"Hello HELLO hello".match(regex);                 // ["Hello", "HELLO", "hello"]

let result = "2025-07-24".match(/(\d{4})-(\d{2})-(\d{2})/);
result[1];     // 2025
result[2];     // 07
result[3];     // 24
```

This is a small and incomplete example of what AxScript can do. For more information, see the Javascript reference.


---

# 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://adaptix-framework.gitbook.io/adaptix-framework/development/axscript/introduction.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.
