A very common misconception is that Java and JavaScript are the same, or even just similar. Here's my favorite analogy for demonstrating how untrue this is:
Java is to JavaScript as car is to carpet
Java and JavaScript are not the same, and they often aren't even used for the same kinds of things.
Java is a statically-typed, object-oriented language that compiles to byte code and runs on the Java Virtual Machine. It's used for all sorts of things, but most commonly for server-side applications, Android apps, and large enterprise systems. If this picture were a programming language, it would probably be Java:

JavaScript is a dynamically and weakly-typed language that runs natively in the browser and out of the browser with dedicated runtimes like Node.js, Deno or Bun. It originally only ran in the browser and was named "JavaScript" because back when it was created in the 90's, Java was very popular and the creators wanted to get a piece of that marketing value.
Brendan Eich, the creator of JavaScript, was given only 10 days to create the language. He was told to make it look like Java, but to make it work in the browser. The rest is history.