I am coming from a C/Python background and the following JavaScript code is puzzling me.
Why is the value of c at the end of the program not 6? Because we are assigning and breaking afterwards. (I have run this on JSFiddle)
function funct() {
var bytes = new Uint8Array(6);
bytes[0] = 228;
bytes[1] = 191;
bytes[2] = 157;
bytes[3] = 233;
bytes[4] = 153;
bytes[5] = 186;
bytes[6] = 255;
bytes[7] = 17;
bytes[8] = 23;
bytes[9] = 223;
var c = 0;
for (var i = 0; i < bytes.length; i++) {
if (bytes[i] == 255) {
c = i;
break;
}
}
console.log(i);
console.log(c);
}
funct();
Output:
6
0