How do Javascript files continuously run?
I'm having a big conceptual problem trying to make a primitive paint app. This is my first "big" project, and I'm hoping to learn how to make interactive webpages with this project. I've learnt how to make static webpages and some interactive elements in html and javascript (e.g <button href="webpage.html">) and understand how that works - the interpreter runs through the code from the top and just does what it reads. And then thats it.
Problem is, how does the js file work? If below </body> I put <script src="main.js>, isn't this file just run .... once? and then the intepreter goes to the end of the HTML file and thats it? Maybe its because the JS file just acts to change the DOM and then it goes from there? No idea really.
My background is in leetcode and scientific programming, wherein I made programs that just ran and then returned a result, so this is my first time making continously running programms.
Thanks very much.
30 comments · 83% upvoted · other discussions
Javascript is triggered by events. For a paint program, you are going to be using mouse events.
https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove\_event