I had a problem while destructuring the result of an String.split() operation.
Situation
This code is present in my index.html page in a <script>
tag, but I tested it with a separate file, and it has the same behaviour
var timestamp = "2023/06/07T15:50:15.655000";
[timestamp_date, timestamp_time] = timestamp.split("T");
console.log(timestamp_date, timestamp_time);
(I also noticed that the code snippet of stackoverflow doesn't throw an error, but isn't printing the result either)
I used Firefox 68.2 and Edge 112.0, and both throws a ReferenceError, saying timestamp_date isn't defined, which I understand, because timestamp_date and timestamp_time are not defined with a var, const or let.
However, when i try to do it in the console, it works just fine.
Also, when I try with a simpler code, it works perfectly without having to define the variables
(It works in the console, but also in a <script>
tag)
[a,b] = ["1","2"]
console.log(a,b);
So my question is : Is it a problem with destructuring and String.split(), or am i missing something ?
EDIT
I know that adding const, let or var before the destructuring works, i just want to know why the second case works without