I think the key thing you need to understand is that the line in question must be considered in the context of the for statement that precedes it.
for (let n in nums) {
nums = nums.filter(val => val == nums[n] || val % nums[n] != 0);
}
At first glance, it may look like "val == nums[n]" will always be true. Let's see why that is not the case.
There are many things to evaluate every time the filter method's function runs:
a) The contents of nums
b) The value of n
c) The value of nums[n]
d) The value of val
e) The value of "val == nums[n]"
f) The value of "val % nums[n] != 0"
These things need to be evaluated for every call in the .filter function.
Let's see what that looks like during the first call in the filter function. During this first call:
a) The contents of nums is {2,3,4,5,6,7,8,9,10}
b) The value of n is 0
c) The value of nums[n] is nums[0], which is 2
d) The value of val is 2
e) The value of "val == nums[n}]" becomes "2 == 2", which is TRUE
f) The value of "val % num[n] !=0" becomes FALSE
So, this first element will be kept in nums because "val == nums[n}]" is TRUE.
Next, filter will evaluate the above for val = 3 and so on.
Once the filter is through with n=0, it will proceed with the n=1.
Remember that nums is being modified during each run of .filter.