Find closest greater and smaller number from a sorted array
First of all, comments would be nice. Speaking in terms of implementation rarely helps another person understand what the code is doing. Especially when the code uses very generic variable names. My general rule to comments is when the code tries to do something clever, write a comment.

You could short-circuit the logic if the array is empty. No sense having the code run if you know ahead of time it does nothing. 

Also, by eliminating cases early, you can start making assumptions. This would allow you to simplify logic or make optimizations to existing logic, turning general-case logic to case-specific logic.

for (let i = 0; i &lt; array.length; i++) {
    if (array[i] &gt;= currentValue) {
        immediateNextIndex = i;
        break;
    }
}


Could be simplified using array.findIndex.

Here's my take on it:



const findPreviousNext = (array, currentValue) =&gt; {
  // Short-circuit the code if the array is empty.
  if(array.length === 0){
    return { next: null, prev: null }
  }

  // Find the index of the closest greater number.
  const closestIndex = array.findIndex(v =&gt; v &gt;= currentValue)

  // A non-existent/negative index is undefined. No need for extensive checks.
  const closestNext = array[closestIndex] || null
  const closestPrev = array[closestIndex - 1] || null
  const lastValue = array[array.length - 1] || null

  // The only special case is the non-existent value (index = -1)
  const next = closestIndex === -1 ? null : closestNext
  const prev = closestIndex === -1 ? lastValue : closestPrev

  // Build the instance (a simple POJO in this case).
  return { next, prev }
}

console.log(findPreviousNext([], 3))
console.log(findPreviousNext([1], 3))
console.log(findPreviousNext([1, 2], 3))
console.log(findPreviousNext([1, 2, 3], 3))
console.log(findPreviousNext([1, 2, 3, 4], 3))