NDVI = ( nir - red ) / ( nir + red )
Among them, nir represents the near-infrared band, which corresponds to the B5 band in Landsat8; red represents the red light band, which corresponds to the B4 band.
normalizedDiffence
This method is the abbreviation algorithm of the (A - B)/(A + B) calculation formula and is commonly used in the calculation of various indices.
code
Map.setOptions("SATELLITE");
var image = ee.Image("LANDSAT/LC08/C01/T1_TOA/LC08_123037_20180611");
Map.centerObject(image, 7);
var ndvi = image.normalizedDifference(["B5", "B4"]);
var visParam = {
min: -0.2,
max: 0.8,
palette: 'FFFFFF, CE7E45, DF923D, F1B555, FCD163, 99B718, 74A901, 66A000, 529400,' +
'3E8601, 207401, 056201, 004C00, 023B01, 012E01, 011D01, 011301'
};
Map.addLayer(ndvi, visParam, "ndvi");