What am I doing & # 8594; JavaScript opeator?

So, I looked at the code that controls the counter on the SO ad page. Then I saw the line where this happened i-->. What does it do?

Here is the complete code:

$(function(){

    var visitors = 5373891;
    var updateVisitors = function()
    {
            visitors++;

            var vs = visitors.toString(), 
                 i = Math.floor(vs.length / 3),
                 l = vs.length % 3;
            while (i-->0) if (!(l==0&&i==0))          // <-------- Here it is!!!
                vs = vs.slice(0,i*3+l)
                   + ',' 
                   + vs.slice(i*3+l);
            $('#devCount').text(vs);
            setTimeout(updateVisitors, Math.random()*2000);
    };

    setTimeout(updateVisitors, Math.random()*2000);

});
+2
source share
4 answers

i-->0matches i-- > 0, therefore, a comparison expression if the calculated value is i--greater than 0.

+13
source

this is not an operator. See this link:

What is the "->" operator in C ++?

var i = 10;

while (i-- > 0)
{
   alert('i = ' + i);
}

Output:

i = 9 
i = 8 
i = 7 
i = 6 
i = 5 
i = 4 
i = 3 
i = 2 
i = 1 
i = 0
+6
source

, . , . , , , , :

var i = 10;
while (i--) {
    // Do stuff;
}
+1
source

Thinking about the same topic that JCasso was thinking about. What is the "->" operator in C ++?

I think this style of code is related to the early days of programming when the terminals had limited display property.

0
source

All Articles