you can execute a . js file in your browser locally, so as @Slayermoah mentioned, save the code into a . js file, and load it in your browser with the url file://path/to/the/file.js .
Use Chrome browser and with the Web Server for Chrome extension, set a default folder and put your linked html/js files in there, browse to 127.0. 0.1:8887 (0r whatever the port is set at) in Chrome and open the developers panel & console. You can then interact with your html/js scripts in the console.
How run js file on local machine?
You can run it in a web browser, just use an html that has an import to the script you’re using. You can view execution in the browser console. In addition to running it in chrome/browser, if you install node, you can just run the js file from the command line with node filename. js .
- Open Chrome on your computer.
- Click. Settings.
- Click Privacy and security.
- Click Site settings.
- Turn on Allowed (recommended).
- Open Terminal or Command Prompt.
- Set Path to where File is Located (using cd).
- Type “node New. js” and Click Enter.
- Add the shbang line to your script.
- If on unix do the chmod +x thing.
- Turn your script into an npm project (if not already an npm project) by putting it into its own folder then running npm init inside that folder (this will create a package.json file)
- Install the Code Runner Extension.