78 segment.matrix.copyToArray(matrixData, segIdx * 16);
79 segment.color.toArray(colorData, segIdx * 4);
80 colorData[segIdx * 4 + 3] = this.getTransparentValue();
81 completed[lineIdx] = false; 82 }
83
84 let box = this.buildBox();
Variables should be used inside of their binding context.
This helps avoid difficult bugs with variable hoisting.
It is a bad practice to use var
declarations because variables declared using var
can be accessed in a function-wide scope.
They can even be accessed before declaration.
In such cases, their value would be undefined
because only declarations and not initializations are hoisted.
function doIf() {
if (cond()) {
var build = true;
}
console.log(build);
}
function doIfElse() {
if (cond()) {
var build = true;
} else {
var build = false;
}
console.log(build)
}
function doIf() {
let build;
if (cond()) {
build = true;
}
console.log(build);
}