TypeScript var VS let (2)
🏷️ TypeScript
var
ts
ts
function sumMatrix(matrix: number) {
var sum = 0;
for (var i = 0; i < matrix.length; i++) {
var currentRow = matrix;
for (var i = 0; i < currentRow.length; i++) {
sum += currentRow;
}
}
return sum;
}
js
js
function sumMatrix(matrix) {
var sum = 0;
for (var i = 0; i < matrix.length; i++) {
var currentRow = matrix;
for (var i = 0; i < currentRow.length; i++) {
sum += currentRow;
}
}
return sum;
}
let
ts
ts
function sumMatrixC(matrix: number) {
let sum = 0;
for (let i = 0; i < matrix.length; i++) {
let currentRow = matrix;
for (let i = 0; i < currentRow.length; i++) {
sum += currentRow;
}
}
return sum;
}
js
js
function sumMatrixC(matrix) {
var sum = 0;
for (var i_1 = 0; i_1 < matrix.length; i_1++) {
var currentRow = matrix[i_1];
for (var i_2 = 0; i_2 < currentRow.length; i_2++) {
sum += currentRow[i_2];
}
}
return sum;
}