What does “!–” do in JavaScript?

I have this piece of code (taken from this question):

var walk = function(dir, done) {
    var results = [];

    fs.readdir(dir, function(err, list) {
        if (err)
            return done(err);

        var pending = list.length;

        if (!pending) 
            return done(null, results);

        list.forEach(function(file) {
            file = path.resolve(dir, file);
            fs.stat(file, function(err, stat) {
                if (stat && stat.isDirectory()) {
                    walk(file, function(err, res) {
                        results = results.concat(res);

                        if (!--pending)
                            done(null, results);
                    });
                } else {
                    results.push(file);

                    if (!--pending) 
                        done(null, results);
                }
            });
        });
    });
};

I’m trying to follow it, and I think I understand everything except for near the end where it says !--pending. In this context, what does that command do?

Edit: I appreciate all the further comments, but the question has been answered many times. Thanks anyway!

10 Answers
10

Leave a Comment