forked from benlcollins/introductionToAppsScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
007_IntroToAppsScript_Variables.js
88 lines (66 loc) · 1.36 KB
/
007_IntroToAppsScript_Variables.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
88
// Global Variables
const SHEET_NAME = 'dataset_2020';
// const
function constExample() {
// const
const x = 30;
//console.log(x);
//Logger.log(x);
// const cannot be reassigned, but the value can change
// TypeError: Assignment to constant variable.
// cannot do this:
// x = 50;
// console.log(x);
// const has block scope
{
console.log(x);
const y = 1;
console.log(y);
}
// ReferenceError: y is not defined
// defined in a child block one level up, not available here
console.log(y);
}
// let example
function letExample() {
let y = 100;
console.log(y);
// can be reassigned
y = 200;
console.log(y);
// cannot redeclare it though
// let y = 300;
// console.log(y);
// block scoped
{
let w = 99;
console.log(w);
}
// variable w not available outside block
//console.log(w);
}
// var example
function varExample() {
var x = 1;
console.log(x);
// can be reassigned
x = 2;
console.log(x);
// var has function scope
{
var newVariable = 1000;
}
console.log(newVariable);
}
// other things to note about variables
function otherNotes() {
// Cannot access 'alpha' before initialization
//console.log(alpha);
//const alpha = 10;
// bad practice to not declare
//alpha = 10;
//alpha = 20;
//console.log(alpha);
// access global variables
console.log(SHEET_NAME);
}