Why javascript variable is not changed in all external JS files

Changed ain the main file. Then turn on a.jsand b.js. JS files have the following contents.

a.js

a+=100;

b.js

a=+200;

And the main file :

<script type="text/javascript">
     a=30;
</script>
<script type="text/javascript" src="js/a.js"></script>
<script type="text/javascript" src="js/b.js"></script>
    a+=90;
    console.log("a = " + a);
</script>

The console shows a=290. Why anot 420 (i.e. 30 + 100 + 200 + 90)? why adoes not change to a.jsand b.js?

+4
source share
2 answers

You wrote the statement +=back. Written as =+ +interpreted as a unary operator +; in other words, you explicitly assign a "positive 200" to the variable (in "b.js").

+8

a =+ 200; 200.

, a += 200;

+2

Source: https://habr.com/ru/post/1570910/


All Articles