Andrey Bushman
Andrey Bushman

Reputation: 12506

Why my variable hasn't its initialized value?

I initialize my constant index variable (inside of case code block) by expression that returns 2. But I see index value is undefined... How it possible?

I created this project through create-react-app command and clear all JS and CSS files in the src subdirectory.

I published code sources of my example here: https://github.com/Andrey-Bushman/i-learn-redux (You can run the project by npm start or yarn start command).

enter image description here

Console output:

enter image description here

The findIndex is native function:

enter image description here

Upvotes: 3

Views: 93

Answers (1)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174329

This is a bug in Chrome DevTools. index does have the value 2 - you will notice this if you console.log(index). It looks like Chrome DevTools has a problem with the index variable being defined twice in this function.
If you rename one occurrence, Chrome DevTools displays the correct value.

Also, in Local you will see another variable _index which has the correct value.

Upvotes: 3

Related Questions