Public static void main(String[] args) {} Won't Work Js

Hey all, just needed a little help understanding why I can’t add public static void main(String[] args) to my Js code.

I Keep running into errors. Also, I can’t seem to locate how to add in the iostream Library to my C++ code files either, I constantly see it used in tutorials. Any help would be greatly appreciated.

This is a Microcontroller forum, so the main programming languages here are C, C++ and Assembly(and some python).

In order to add iostream to your codebase you need to include the standard library header <istream>with

#include <istream>

To my understanding Javascript has no main function, as Javascript is not directly used to program applications(with some frameworks it is, but then you gotta learn the framework), but to program dynamic websites. Javascript in a web browser context can for example wait for events to be executed(for example waiting for the whole website to be loaded(and the DOM fully constructed) and then execute the wanted function). If I’m not mistaken, you can write javascript code directly in the *.js file without declaring any main function. Also depending on where your <script> tag is placed in the html file, the execution of the JS code is different.
Javascript works on the DOM, basically the website structure, and on an omnipresent document object.

Java on the other side has exactly that main function syntax.

1 Like