DEV Community

Discussion on: How can I detect the presence of varargs in JS function?

Collapse
findoff profile image
abnessor aka findoff • Edited on

Rest operator supports 0 or more args. Btw it's don't count as existing argument.
As i know, at this moment no ways to detect it other than toString().

function f(a, ...args) {return args;} // length count only real arguments
f.length // 1
f.toString() // "function f(a, ...args) {return args;}"
Enter fullscreen mode Exit fullscreen mode