In the following example
<!DOCTYPE html>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
var str = '11';
str = str++;
alert(str); // 11
</script>
why is the result 11 and not 12?
In this example the result is 12:
<!DOCTYPE html>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
var str = '11';
str++;
alert(str); // 12
</script>
Why is this so?
Thank you!
var str = 10;
var re = str++;
alert(re); // 10
alert(str); // 11
str will return 10 to re first, and then increments str itself to 11.
But
var str = 10;
var str = str++;
alert(str); // 10
In this case, str return 10 to str first, and then str should increments str itself to 11.
But it doesn't. Can anyone explain this?
Thank you!