javascript - how this for loop determines when to break the loop -
I have encountered a different type of loop which I do not normally see or do not use. I tried to understand it, but this process is even more confusing. There is no check method to break the third argument or loop. Here it is recursive on an array and prints its value. In fact, it faces the 'undefined' value for a certain index, but I'm not telling it to break when it will face an undemocratic encounter. Please help me break the puzzle ...
(function () {var a = [1, 2, 3, 4, 5, 6, 7, 8, 9]; (var i = 0, value; value = a [i ++];) {document.write (value + '& lt; / br & gt;'}}}) ();
In Javascript, when you use the array length Beyond access array elements, you do not receive a boundary check error, ret blue value is related to undefined which is related to false when used as a boolean - Thus the loop termination when the end of the array reaches the end. If any array element is undefined or any other value that is in the form of a false boolean, the loop will end on that element. The assignment operator in the Javascript return is the left side value, hence the expression value = a [i ++] is used by a [i] and increments The value of i is done - in that order. If this value is converted to Boolean as false , the loop is terminated.
Comments
Post a Comment