Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
    }
});
like image 595
Pompeyo Avatar asked Jan 17 '14 14:01

Pompeyo


2 Answers

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).

like image 158
Quentin Avatar answered Sep 28 '22 09:09

Quentin


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;
......
like image 40
Vlad Nikitin Avatar answered Sep 28 '22 09:09

Vlad Nikitin