What is the difference between Array.from and Array.of?
They solve different problems. Array.of takes its arguments and makes them the contents of a new array, so it always creates an array of exactly the values you passed to it. Array.from takes something you can walk through, such as a set or a string, and creates an array from what it finds there.
console.log(Array.of(1, 2, 3)); // [1, 2, 3]
console.log(Array.from('abc')); // ['a', 'b', 'c']
console.log(Array.from({ length: 3 })); // [undefined, undefined, undefined]
// The trap: one number sets the length, not the contents.
console.log(Array(3)); // three empty slots
console.log(Array(1, 2, 3)); // [1, 2, 3]
console.log(Array.of(3)); // [3]
The trap at the end is the one that interviewers like. Calling Array with a single number creates an array with that many slots and no values in them, which is completely different from what it looks like it should do. Array.of does not have that special case, so Array.of(3) is an array that holds the number three. That makes Array.of the safer choice whenever the values come from a variable, because it does the obvious thing.
Array.from is the more useful of the two in everyday code. It turns anything you can walk through into an array, so it works with sets, maps, strings, the arguments object, and generators. It also takes a second argument, which is a function that is applied to each value while the array is being built. That saves you a separate step and an extra array.