Selenium is an open-source framework it also helps you automate the browser. What Javascript does is it becomes an executor which allows you to run pure Javascript code irrespective of the Selenium language binding(Java, C#, Python etc.) you are using.
The advantage of using JavaScript is that you can directly interact and alter elements on the page, more or less, as the page developer has done. Javascript being a language which works very well with HTML offers innumerous workarounds/hacks on the page. This comes in handy in such scenarios where the Selenium library function does not work for you. So, instead of using the library function, you write a Javascript snippet which would work and make it run through the Selenium’s Javascript Executor. You can take up the following Selenium Training course which will help you to learn it better with a valuable certificate, it will also help you to get the right job. If you are more into reading you must read the following Selenium Tutorial. Here is the video tutorial which will help you to clear all your doubts regarding Selenium. .