Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the easiest way to run a .js javascript file on windows?

Tags:

javascript

When you try and run (not edit) a Javascript file, It will give an error that sounds like it is missing a reference in your code. For Example, I got:

Line: 3 Char: 1

Error: 'document' is undefined'

Code: 800A1391

Source: Microsoft JScript runtime error

Is it trying to execute a program similar to VBScript? Should I be running it with another program?

like image 533
N Barns Avatar asked Oct 20 '25 01:10

N Barns


1 Answers

Windows Script Host (WSH) is a Microsoft technology used to run script files in various languages: it connects a script file with a script engine to run it. It has been around since Windows 95 and it's documentation can be found on the web.

If you double click on a .js file, and if WSH has not been disabled, it results in Microsoft's "JScript" script engine being run to execute the script with JavaScript bindings for the execution environment which include access to the file system and shell. It does not provide a browser environment or HTML rendering, so document flags as undefined.

To run a browser script, run it in a browser. Systems scripts might be written to run under WSH but there is a newer "PowerShell" replacement under Windows. NW.js and Node.js provide alternative cross platform capabilities and features.

Note that the name "JScript" originated during browser wars of the last century. Let's not go there ;-)

like image 123
traktor Avatar answered Oct 21 '25 16:10

traktor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!