You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: GEMINI.md
+26-9Lines changed: 26 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ pnpm format
21
21
22
22
Apps Script supports the V8 runtime, which enables modern ECMAScript syntax. Using these features makes your code cleaner, more readable, and less error-prone.
23
23
24
-
### 1. `let` and `const`
24
+
### `let` and `const`
25
25
Use `let` and `const` instead of `var` for block-scoped variables.
26
26
27
27
***`const`**: Use for values that should not be reassigned.
@@ -37,15 +37,15 @@ if (true) {
37
37
// local is not accessible here
38
38
```
39
39
40
-
### 2. Arrow Functions
40
+
### Arrow Functions
41
41
Use arrow functions for concise function expressions, especially for callbacks.
42
42
43
43
```javascript
44
44
constnumbers= [1, 2, 3];
45
45
constsquares=numbers.map(x=> x * x); // [1, 4, 9]
46
46
```
47
47
48
-
### 3. Destructuring
48
+
### Destructuring
49
49
Unpack values from arrays or properties from objects into distinct variables.
50
50
51
51
```javascript
@@ -56,7 +56,7 @@ const coords = [10, 20];
56
56
const [x, y] = coords;
57
57
```
58
58
59
-
### 4. Template Literals
59
+
### Template Literals
60
60
Use template literals for string interpolation and multi-line strings.
61
61
62
62
```javascript
@@ -69,7 +69,7 @@ const multiLine = `
69
69
`;
70
70
```
71
71
72
-
### 5. Default Parameters
72
+
### Default Parameters
73
73
Specify default values for function parameters.
74
74
75
75
```javascript
@@ -80,6 +80,23 @@ function greet(name = "Guest") {
80
80
greet(); // "Hello, Guest!"
81
81
```
82
82
83
+
### Prefer `for...of` for Iteration
84
+
While `forEach` is convenient, `for...of` loops generally offer better performance and more control (e.g., `break`, `continue`) in Apps Script, especially when dealing with large arrays.
85
+
86
+
```javascript
87
+
constnumbers= [1, 2, 3];
88
+
89
+
// Using forEach (less performant for large arrays)
90
+
numbers.forEach(num=> {
91
+
console.log(num);
92
+
});
93
+
94
+
// Using for...of (preferred)
95
+
for (constnumof numbers) {
96
+
console.log(num);
97
+
}
98
+
```
99
+
83
100
## Apps Script V8 Runtime
84
101
85
102
It's important to understand that the Apps Script V8 runtime is
@@ -237,7 +254,7 @@ function greet(name, age) {
237
254
238
255
### Advanced Patterns
239
256
240
-
#### 4. Custom Objects (@typedef)
257
+
#### 1. Custom Objects (@typedef)
241
258
For complex objects, define a type using `@typedef`.
242
259
243
260
```javascript
@@ -257,7 +274,7 @@ function processUser(config) {
257
274
}
258
275
```
259
276
260
-
#### 5. Type Casting
277
+
#### 2. Type Casting
261
278
Sometimes the type checker cannot infer the type correctly. Use inline `@type` to cast.
262
279
263
280
```javascript
@@ -267,7 +284,7 @@ const data = JSON.parse(jsonString);
0 commit comments