How React is able to access the variable before initialization?

function app() {
  console.log(myVariable);
}
app();
const myVariable = "hello world";

I understand that the above code snippet produces an error because I am try to access a const variable before initializing it but the code below doesn’t give me any error even though I am trying to access myVariable before initialization. why is it so? How am I able to access myVariable even before initializing it ?

import { createRoot } from "react-dom/client";

const rootElement = document.getElementById("root");
const root = createRoot(rootElement);

function App() {
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      {console.log(myVariable)}
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}

root.render(
    <App />
);

const myVariable = "hello world";