3 ms·
Fun distraction. For me it was: 30% figuring out the answer, 20% not having my editor shortcuts available, 50% figuring out how to check if a value is a certa
by peeters 13y ago
Fun distraction. For me it was:
30% figuring out the answer, 20% not having my editor shortcuts available, 50% figuring out how to check if a value is a certain type.
Am I the only one that gives their functions preconditions that the input is good? To me, throwing up when you're passed a non-number to a sum method is correct behavior.
- dclowd9901 13y agoTIL there is no typeof === 'array'. -_-
- ep103 13y agoArray.isArray(yourVariable), yeah, had to mdn that one too.
- rhengles 13y ago[] instanceof Array; // returns true
- dclowd9901 13y agoClever...
- bentruyman 13y agoHowever this fails on "Array-like" objects like NodeLists.
- hayksaakian 13y agotypeof(["an array", "contains multiple things"]) == typeof(["sometimes"])
- iclelland 13y agoYes, but: typeof(["an array", "contains multiple things"]) == typeof({but_this_one: "is an object"})