There are similar questions here but they didn't really answer my questions.

So I am curious why we can't declare the same variable twice in Java?

for example:

```
  int a = 4;
  int a = 6;

```

this won't really work in Java.

However in javascript, this actually works:

```
var a = 1;
var a = 2;

```

In javascript, people said that the declaration immediately got moved to the start so that it became like this:

```
var a;
a = 1;
a = 2;

```