Pompeyo
Pompeyo

Reputation: 1469

How to avoid unused variables with JavaScript?

What is a good JavaScript technique/convention/standard to avoid unused variables?

For example, if I'm calling a function like below and I just want to use the 3rd parameter, what do I do with the 1st and 2nd parameters?

$.ajax({
    success: function(first, second, third){
        console.log("just using: " + third);
    }
});

Upvotes: 6

Views: 2464

Answers (2)

Vlad Nikitin
Vlad Nikitin

Reputation: 1951

this first, second params if they have no references will be deleted by Garbage collector, to help him to do it you can make next in the start of your function

success: function(first, second, third){
first = second = null;
......

Upvotes: 2

Quentin
Quentin

Reputation: 943579

Ignore them.

(You could define your function as function () { and then use var third = arguments[2]; but that doesn't lend itself to very readable code).

Upvotes: 3

Related Questions