Client vs Server Objects

Earth Engine code runs in two places: your browser (client) and Google's servers (server). Knowing the difference prevents many errors and keeps scripts fast.

Learning objectives

  • Distinguish client-side JavaScript objects from server-side ee objects.
  • Use ee methods (like .add()) instead of JavaScript operators.
  • Avoid mixing client and server data in the same expression.
  • Know when to use print() vs evaluate().

Why it matters

The server holds petabytes of imagery and does the heavy computation. Your browser cannot store or process that data. Writing server-friendly code lets Earth Engine scale for you.

Two worlds

  • Client (browser): plain JavaScript numbers, strings, arrays, dates.
  • Server (Earth Engine): ee.Number, ee.String, ee.List, ee.Image, ee.Feature, ee.ImageCollection, and more.

What works vs what breaks

// This breaks (mixing client and server):
var serverNumber = ee.Number(5);
var bad = serverNumber + 10; // cannot add client number with +

// This works (use server methods):
var good = serverNumber.add(10);
print('Result:', good);

Key concepts

  • Objects starting with ee. live on the server.
  • Use ee methods: add, subtract, map, reduceRegion, etc.
  • print() sends a request and fetches a small preview; evaluate() returns data to the client asynchronously when you truly need it.
  • .map() runs on the server; do not include client-only calls like Map.addLayer inside it.

Common mistakes

  • Using +, -, * on ee objects instead of .add(), .subtract(), .multiply().
  • Using JavaScript for loops to iterate server collections-use .map() or reducers instead.
  • Calling .getInfo() on large objects, freezing the browser; prefer print() for inspection.

Hands-on: fix a broken line

// Fix the line below without using +
var number = ee.Number(3);
var sum = number /* add 7 here the right way */;
print('Sum:', sum);

Expected output

The console shows 10 when you use number.add(7).

Try it: practice conversions

Wrap a client-side list in ee.List and print it.

Create a client number and convert it to ee.Number before multiplying.

Use evaluate() to retrieve a small server value to the client and log it.

Quick self-check

  1. Why does serverObj + 1 fail-
  2. When should you use .map() instead of a for loop-
  3. What is the safer default: print() or getInfo()-

Next steps