There are a couple of ways to calculate the area of the image in the Google Earth Engine. The full implementation of both method can be accessed using this link.

  1. Pixel Count Method
    We can calculate the area of the image by counting the total number of unmasked pixels in that image. Then, multiply the total number of unmasked pixels by the scale factor to get the area in square meters. An implementation for this is shown below.

    var countries = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw');
    var Nepal = countries.filterMetadata('Country', 'equals', 'Nepal');
    
    var testAreaImage = ee.Image(1).clip(Nepal);
    var scaleforTestArea = 30;
    
    var reducer = testAreaImage.reduceRegion({
      reducer: ee.Reducer.sum(),
      geometry: Nepal,
      crs: 'EPSG:32645', // WGS Zone N 45
      scale: scaleforTestArea,
      maxPixels: 1E13
    });
    // km square
    var area = ee.Number(reducer.get('constant')).multiply(scaleforTestArea).multiply(scaleforTestArea).divide(1000000);
    // gives an area of 147502.63 km2
    print('area of Nepal using pixel count method: ', area.getInfo() + ' km2');
    
  2. Pixel Area Method (Recommended)
    The other method to calculate the area in the Google Earth Engine is to calculate the area of each unmasked pixel. Then, get the sum of all the pixel areas to calculate the area of the image. An implementation for the same area as above is shown below. Clearly, one can see that the second method works better than the first method.

    var countries = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw');
    var Nepal = countries.filterMetadata('Country', 'equals', 'Nepal');
    var scaleforTestArea = 30;
    
    // km square
    var img = ee.Image.pixelArea().divide(1000000);
    
    var area2 = img.reduceRegion({
      reducer: ee.Reducer.sum(),
      geometry: Nepal,
      crs: 'EPSG:32645', // WGS Zone N 45
      scale: scaleforTestArea,
      maxPixels: 1E13
    });
    // gives an area of 147134.49 km2
    print('area of Nepal using pixel area method: ', ee.Number(area2.get('area')).getInfo() + ' km2');