What is the function of JavaScript
It’s a programming language designed for manipulating web browsers. Like, you need to program something interactive on a web page that isn’t supported out-of-the-box. Instead of rewriting the code for the entire browser and building a new version of it, you can just write a “script”, a file with some instructions in JavaScript, and the browser can read that and apply your functionality to the web page you want it to apply to.
JavaScript is a general-purpose programming language, so nowadays you can do most stuff you would be able to do using other programming languages for, it’s not just used in web browsers.