How do I output the name of a PARAMETER in js?

function CreateNewElement(tag, css){
console.log(tag);
 this.css = css;
 this.tag = tag;
try{
 for(let i = 0; i<arguments.length; i++){ if(arguments[i]="=" undefined){ throw new error("Missing argument" + arguments[i]); (1) } console.log("a html tag has been created: \n <"+tag+" style="\""" css "\">");
}catch(e){
 alert(e.name + "\n" + e.message);
}
};
var div = new CreateNewElement(undefined, "color:white;");</arguments.length;>

Displays the value of the argument passed. Necessary - the name of the PARAMETER, that is, in this case, the tag I'm trying to achieve this without creating an array with parameters and then its stupid to call through [i]. Need something uneversalna
June 10th 19 at 15:14
2 answers
June 10th 19 at 15:16
Solution
If the name parameter you mean the parameter name, for JS it is impossible in a generic way. Easier it will be to the function passing an object as argument.
June 10th 19 at 15:18
Solution
1) the Parameter is the argument, if that.
2) in any Way.
3) Validate parameters individually:
if (tag === undefined) {
 throw new Error('please choose tag'); 
}

or specify default values:
tag = tag || '
';

4) Your cycle still wouldn't work because of arguments.length will meet the real number of passed parameters and not as it should be. That is, if you just run CreateNewElement() without parameters, then no error will.
Parameters and arguments are different things.
The parameters are specified in the function Declaration.
Arguments are specified when calling the function. - maxie.Mo commented on June 10th 19 at 15:21
understood, thank you. But sure benefit from such knowledge is purely academic. - Pablo63 commented on June 10th 19 at 15:24

Find more questions by tags JavaScript