This question already has an answer here:
I have the following code below:
function test(arr, initialValue) {
console.log(initialValue)
if (initialValue === {}) {
let reverseStr = {};
} else {
let reverseStr = '';
}
console.log(reverseStr)
}
test(['a', 'b', 'c', 'd'], {})
I am expecting the invoked function to console log {}. Instead, I get ReferenceError: reverseStr is not defined
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire