Functions

While using Earth Engine, you will need to define your own functions. Functions take user inputs, use them to perform some computation, and send output back. Functions allow you to group a set of operations and repeat the same operations with different parameters without having to rewrite them every time. Functions are defined using the function keyword.

The code below defines a function called greet that takes an input called name and returns a greeting with Hello prefixed to it. 

var greet = function(name) {
  return 'Hello ' + name;
};

print(greet('Albert Gator'));
print(greet('Alberta Gator'));

Note that we can call the function with different inputs, and it generates different outputs with the same code. This is the power of functions: you can create blocks of codes that act as tools.  Your output should look like this after running it in Earth Engine. 

output from google earth engine after writing a comment.