Javascript function to get cellId from map point
I always like to document my functions using high-level doc-blocks, e.g.

/**
 * Return the ID of the cell whose center is at the given point or -1 if ...
 *
 * @param {number} x - The x coordinate of the given point.
 * @param {number} y - The y coordinate of the given point.
 * @return {number} cell ID or -1 if no cell found at given point.
 */
const getCellIdFromMapPoint = (x, y) =&gt; { ... }


Also, I use inline comments to help the reader and my future self to understand complex statements such as

// Do C if A and B or C:
if (x &lt; offsetX &amp;&amp; y &lt; offsetY) 
   if ((offsetY - y) / (cellCoordinates.x - x) &gt; (offsetY - cellCoordinates.y) / (cellCoordinates.x - offsetX)) return cellId


Better yet, take those complex statements as a hint to better refactor your code.

I advise to use available language constructs where appropriate. If you replace a simple for-loop with a while-loop for no apparent reason, a fellow developer will have a harder time to read and understand your code.

Also, I really recommend to use curly brackets with if-statements. The lack of those might be more pleasing to the eye by hiding the deep nesting, but makes reading and understanding as well as modifying your code much harder.

I suggest to combine if-clauses with identical statements. Instead of writing e.g. 

if (A)
  if (B)
   return cellId;
if (C)
  if (D)
   return cellId


write e.g.

if ((A &amp;&amp; B) || (C &amp;&amp; D)) {
  return cellId;
}


Better yet, write helper functions to reduce the complex conditions, e.g.

if (isSomeCondition(A, B) || isSomeOtherCondition(C, D)) {
  return cellId;
}


Give those functions clear, self-documenting names to help the reader along. In your case, those could be e.g. isWithinRect(x, y, rect) or similar.

Your algorithm's runtime complexity is probably linear in the number of available cells. If you find that your application is running slow because of that, you can employ techniques such as spatial partitioning to improve runtime performance.