Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my variable hasn't its initialized value?

Tags:

javascript

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

like image 329
Andrey Bushman Avatar asked Mar 27 '26 16:03

Andrey Bushman


1 Answers

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.

like image 197
Daniel Hilgarth Avatar answered Mar 29 '26 06:03

Daniel Hilgarth