how javascript works

JavaScript
JavaScript is what is called a Client-side Scripting Language. ... Inside a normal Web page you place some JavaScript code (See How Web Pages Work for details on Web pages). When the browser loads the page, the browser has a built-in interpreter that reads the JavaScript code it finds in the page and runs it.
Source

Also in JavaScript: