Write in the beginning: personal “talent and learning”, small white one, the following content is the summary of notes in the learning process and personal feeling, if there is any mistake please correct

About the title: the title is the road to Cultivation. One is that I used to be a fan of fairy cultivation novels, and the other is that I was inspired by a book written by The great God Yang Yifei


Today, I will explain (in my opinion only) the reasons for the problem:

Above address: The road to JavaScript training — practice gas section, JS related syntax

Var I = 10,j; var I = 10,j; var I = 10,j; var I = 10,j; var I = 10,j; j = i++ ; Why does console(j) output 10 instead of 11, and doesn’t that result violate the precedence order of the operator?


Preliminary knowledge

The JVM instruction set

Note: After all, we are still in the beginning stage of learning the front-end, so we only understand two concepts here.

Local variable scale

Local Variable Table is a set of Variable value storage space used to store method parameters and Local variables defined in methods

In this case, the function of the local variable table is to generate a storage space, and declare the variable name to the address of the space.

In human terms, every time you declare a variable, you generate a box in the local variable table that you can put things in.

The operand stack

An Operand Stack, also known as an operation Stack, is a LIFO Stack.

In this case, the function of the operand stack is to connect specific values in the code to boxes in the local variable list by pushing them on and off the stack (following the FILO principle: first in, last out)

In English, you buy what you want to put in a box from the store (operand stack) and put it in a box.

Specific implementation process

  1. var i = 10;

The overall flow of this code:

  1. var j = i++;

The overall flow of this code:

Explanation:

We can see from the above figure that I ++ is actually the first I value 10 in the store (operand stack), then I ++ to get the second item 11, and also put it in the store (operand stack). Then according to the FILO principle mentioned above, FILO: First in last out (the item put in first is at the bottom of the shelf, and can only buy the item in front of it at the end of the shelf), the item which is executed first will be put into the box (assigned value) I (local variable scale) after it is bought. Finally, I bought 10 and put it in j’s box.

conclusion

Any unary operator, such as increment or decrement, is always performed in a higher order than the assignment operator, regardless of whether it is pre-increment/subtraction or post-increment/subtraction.

conclusion

This article is just a personal search through the relevant information to their own understanding of the answer, so can not be authoritative, can only help to understand!!