Is there a main () method like java that can be run directly in js?

is there a main () method like java in js that can be run directly in writing?

Mar.05,2021

all statements of reasonable js are run directly, such as executing

with node
//main.js
console.log("It's ok");

I think what you mean is that you see a lot of defined classes and functions but don't use them, so it looks like no statements are executed.

function print(){
  console.log("It's ok");
}
// print()

(function main(){
    //main
})()

so here's the problem. We all know that JAVA's main () method runs directly. Why? Sit and wait for the boss downstairs to answer.


do you want the page to be running as soon as it is loaded?

window.onload=function(){
    mian();
}
function mian(){
  console.log("mian");
}

js is an interpreted language, which does not need to be compiled and run directly. Which file you run, which file is the entry
Java is a compiled language, and needs to be compiled and run on JVM , so there is an entry function that makes it easy to find entry


any function that executes immediately is like this.
you don't even have to write a function

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea92a9-47cfb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea92a9-47cfb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?