Simple Javascript Solution
\nvar diagonalSum = function(mat) {\n    let primary = 0,\n        secondary = 0;\n    \n\t// storing the sum of all vaues in both diagonals \n    for(let i = 0
```\nvar diagonalSum = function(mat) {\n    let primary = 0,\n        secondary = 0;\n    \n\t// storing the sum of all vaues in both diagonals \n    for(let i = 0; i < mat.length; i++) {\n        primary += mat[i][i];\n        secondary += mat[i][mat.length - i - 1];\n        \n    }\n    \n\t// if its an odd matrix then we subtract the mid item form the total sum. Else we just return the primary and secondary sum;\n\t\n    if(mat.length === mat[0].length && mat[0].length % 2 !== 0) {\n        let centerIdx = Math.floor(mat.length/2);\n        return primary + secondary - mat[centerIdx][centerIdx];\n    } else {\n        return primary+secondary;\n    }\n};\n```
['JavaScript']