'While destructuring array in javascript redeclaration error shown?
Solution 1:[1]
Prior Chrome 92, it was not possible to redeclare the same const
in the console in different executions.
https://developer.chrome.com/blog/new-in-devtools-92/#const-redeclaration
I think you could just update your chrome and your code will work (I just tried it) ;)
Solution 2:[2]
NOTE: This is not an answer, just a suggestion.
when running code in the browser, please run it inside a function and then call that function. This will help you avoid scope issues which might be the case in your question.
I am adding an example here
function test(){
const value = [1, 2, 3, 4];
const [a, b, c] = value;
console.log(a, b, c);
}
test()
This is what you should try to follow. Benefits of following this:
- can be called multiple times without writing the whole code every time
- can pass arguments in the function to make it dynamic
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Patrick Ferreira |
Solution 2 | gyan roy |