Sign in
Log inSign up

Getting Error regarding scope in javascript

Default profile photo
Anonymous
·Mar 7, 2018

let cards = ['Diamond', 'Spade', 'Heart', 'Club'];

let currentCard = 'Heart';

while (currentCard !== 'Spade') {
  console.log(currentCard);
  let currentCard = cards[Math.floor(Math.random() *4)];
}

console.log(currentCard);

Here myConcern is about the error that currentCard is not defined ,eventhough I have declared it globally .

So I am thinking that the error message currentCard is not defined should not come.