Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Arguments Preference [closed]

Just a style question.

do you people prefer to pass in variables into a function like

function (a, b) {
    return a + b;
}(1,2);

or 

function (args){
    return args.a + args.b;
}({a:1;b:2});

?

Are there any performance issues between the two?

I'm deciding on standardizing my functions in some way, therefore I'm asking this question.

like image 214
blinkomania Avatar asked May 20 '26 01:05

blinkomania


1 Answers

If it's just a few parameters I would use the first for better readability (documentation).

If there are a lot of parameters, I would use the second one (for example options object).

I don't think there's any major performance difference between the two.

like image 198
Mario S Avatar answered May 22 '26 13:05

Mario S