Longest Consecutive Sequence
num is only used within the while loop and not outside of it.
A for loop is more appropriate for such pattern.

The solution looks as if you forgot to perform a final refactoring to clean things up.
The function starting with let longestStreak = 1; looks like a good idea,
as the exercise is looking for the longest streak, and at this point,
my expectation is that this variable will be probably returned at the end.
But no, to my surprise it is reset to 1 in the forEach,
and at the end the function returns max.

All that to say, it would make more sense to use a local length variable inside the forEach, and update longestStreak when a higher value is found,
and return it at the end.

var longestConsecutive = function(nums) {
  const set = new Set(nums);
  let longestStreak = 0;
  set.forEach(x =&gt; {
    if (!set.has(x - 1)) {
      let length = 1;
      for (let num = x + 1; set.has(num); num++) { ++length; }
      longestStreak = Math.max(longestStreak, length);
    }
  });
  return longestStreak;
};