Question 9
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const found = "abc".match(/\d/g);
console.log(found, found?.length ?? 0, ("abc".match(/\d/g) || []).length);
- A [] 0 0
- B undefined 0 0
- C null undefined 0
- D null 0 0 Correct
Correct Answer: Option D
match returns null – not an empty array – so length must be guarded with ?. / ?? or by defaulting to [].
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!