JavaScript: Find the number in an array which is closest to an given number
Your main questions


  
  Can I expect my implementation to solve the task in a correct way?
  


You should know that the answer is "yes" before posting a question on Code Review.


  
  Was it a good idea to initialize the 'closest'-variable with the value of the 'compareNumber'-parameter?
  


No, it's a mistake. The function incorrectly returns 0 for input [10, 9], 3.
When looking for the minimum distance,
you must choose as the default the largest possible number.
For example if you target ES6, then Number.MAX_SAFE_INTEGER.


  
  Was it a good idea to check for 'currentDistance &lt; closest'? Or should I have used 'currentDistance &lt;= closest'?
  


That depends entirely on the specification.
If you're looking for the first closest index, then use &lt;.
If the last, then use &gt;.

If the specification was not clear,
then ask to clarify.

Naming

The names are overly verbose.
When short names are sufficient, they are better than long names.

For example,
in a function to find the closest index to a number,
the array parameter is obviously for searching,
so instead of arrayToSearch, it could be simply nums,
and compareNumber could be target.

I would have written like this:

function indexOfClosest(nums, target) {
  let closest = Number.MAX_SAFE_INTEGER;
  let index = 0;

  nums.forEach((num, i) =&gt; {
    let dist = Math.abs(target - num);

    if (dist &lt; closest) {
      index = i;
      closest = dist;
    }
  });

  return index;
}