Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

javascript - How does += (plus equal) work?

I'm a bit confused with the += sign. How does it work?

  1. 1 += 2 // equals ?

  2. and this

    var data = [1,2,3,4,5];
    var sum = 0;
    data.forEach(function(value) {
        sum += value; 
    });
    sum = ?
    
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

1 += 2 is a syntax error (left-side must be a variable).

x += y is shorthand for x = x + y.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...