'Why String.prototype.match() returns null instead of empty array?
Example taken from MDN webdocs
var paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
var regex = /[A-Z]/g;
var found = paragraph.match(regex);
console.log(found); // will return an array of matches and returns null when nothing matches.
Would like to know reasoning behind returning null instead of an Empty Array when nothing matches?
Solution 1:[1]
Probably also because Boolean([]) returns true
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aziz |
