forked from benlcollins/introductionToAppsScript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
008_IntroToAppsScript_Operators.js
89 lines (60 loc) · 1.71 KB
/
008_IntroToAppsScript_Operators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function mathOperators() {
const a = 10;
const b = 2;
// standard operators + - * /
console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
// Raise to power of
const c = Math.pow(a,b);
console.log(c);
// need to use let in this next example because of reassignment by the i++ and i--
let i = 0;
console.log(i);
// increment by 1
i++;
console.log(i);
// reduce by 1
i--;
console.log(i);
}
function stringOperators() {
// can use single or double quotes around strings
// BUT MUST BE CONSISTENT WITHIN LINE
const string1 = "Sarah"; // ok
const string2 = 'Smith'; // ok
const string3 = 'John'; // not ok
// concatenate strings with the plus sign +
const fullName = string3 + " & " + string1 + " " + string2;
console.log(fullName);
// multi-line strings with backtick marker
const multiLineString = `This is a multi-line string
in Apps Script, which is handy for those long paragraphs.`;
console.log(multiLineString);
}
function comparisonOperators() {
const a = 10;
const b = '10';
console.log(a);
console.log(typeof a);
console.log(b);
console.log(typeof b);
// double ==
console.log(a == b);
// triple === now checks to see if the type is matching too
console.log(a === b);
// Not equal !=
console.log(a != b);
// false becuase javascript does type conversion and so values are equal
// Not equal when considering value AND type !==
console.log(a !== b);
// true becuase the type is not equal
// Greater than, less than operators
const c = 50;
const d = 100;
console.log(c > d);
console.log(c >= d);
console.log(c < d);
console.log(c <= d);
}