Question 16
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log(Array(3).length, Array.of(3).length, Array(3, 4));
- A 1 1 [ 3, 4 ]
- B 3 1 [ 3, 4 ] Correct
- C 3 3 [ <3 empty items>, 4 ]
- D 3 1 [ <3 empty items> ]
Correct Answer: Option B
Only a single numeric argument means "length". With two arguments the constructor creates those elements; Array.of always does.
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!