Javascript Validation Function Parameters

How to check that a function has not received arguments? For example, I want to be able to create a user-defined function that accepts multiple inputs like this:

clear(); // clear all clear('a'); // clear a clear('b'); // clear b clear('c'); // clear c clear('d'); // clear d 
+4
source share
1 answer

You can check if the argument matches undefined :

 function clear(variable) { if (variable === undefined) { ... } } 

or just check the number of arguments :

 function clear(variable) { if (arguments.length === 0) { ... } } 
+7
source

All Articles