GEE中的JavaScript简单介绍
正式进入GEE编程,这里先简单讲一下GEE开发使用的编程语言。网页端的工作空间使用的语言是JavaScript,但是谷歌对其又做了稍微修改使其变为自己的编程语言规则。所以只要开发者掌握简单的JavaScript的开发,编写GEE代码完全没有问题。
简单的JavaScript语言介绍,具体语法等需要自己参考Google或则百度。
//这个例子包含了GEE开发中常见的所有的JS内容,数据类型包括字符串、数值、布尔值、对象、列表、条件判断、循环、函数
//string
var str = "hello world!";
print(str);
//number
var age = 12;
print("age is " + age);
var percent = 0.02;
print("percent is " + percent);
//bool
var flag = true;
//condition
if (flag) {
print("this is true");
} else {
print("this is false");
}
//list
var names = ["a", "b", "c"];
print(names);
//for loop
for(var n in names) {
print("for loop is " + n);
}
//while loop
var index = 0;
while (index < names.length) {
print("while loop is " + names[index]);
index ++;
}
//object
var info = {
name: "ABC",
age: 20,
desc: "this is a boy!"
};
print(info);
print("age is " + info["age"]);
print("name is " + info.name);
//function
var add = function(a, b) {
return a+b;
};
print("10 + 20 = " + add(10, 20));
function sub(a, b) {
return a-b;
}
print("20 - 10 = " + sub(20, 10));
在GEE中运行输出结果