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;
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
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;
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
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;
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
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;
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10