14

What are the JavaScript compilers or interpreters available for Windows?

I read the book Eloquent JavaScript recently. This book introduces the reader to programming using JavaScript as the first language. Sadly, the programs are restricted to run inside the browser embedded in HTML. So, I wonder if it is possible to write JavaScript programs that can be executed standalone.

The compiler or interpreter should be easily available as a pre-compiled binary that can be downloaded and installed by a beginner. He should be able to write simple standalone JavaScript programs that are compiled with this compiler. Additional JavaScript libraries, frameworks, IDEs and debugging support that would work with this compiler would be a plus.

Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292

9 Answers9

12

Nobody has mentioned yet, window's own javascript compiler: http://msdn.microsoft.com/en-us/library/vstudio/7435xtz6(v=vs.100).aspx

Microsoft (R) JScript Compiler version 8.00.50727
for Microsoft (R) .NET Framework version 2.0.50727
Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.

jsc [options] <source files> [[options] <source files>...]

                         JScript Compiler Options

                           - OUTPUT FILES -
  /out:<file>              Specify name of binary output file
  /t[arget]:exe            Create a console application (default)
  /t[arget]:winexe         Create a windows application
  /t[arget]:library        Create a library assembly
  /platform:<platform>     Limit which platforms this code can run on; must be x86, Itanium, x64, or anycpu, which is the default

                           - INPUT FILES -
  /autoref[+|-]            Automatically reference assemblies based on imported namespaces and fully-qualified names (on by default)
  /lib:<path>              Specify additional directories to search in for references
  /r[eference]:<file list> Reference metadata from the specified assembly file
                           <file list>: <assembly name>[;<assembly name>...]

                           - RESOURCES -
  /win32res:<file>         Specifies Win32 resource file (.res)
  /res[ource]:<info>       Embeds the specified resource
                           <info>: <filename>[,<name>[,public|private]]
  /linkres[ource]:<info>   Links the specified resource to this assembly
                           <info>: <filename>[,<name>[,public|private]]

                           - CODE GENERATION -
  /debug[+|-]              Emit debugging information
  /fast[+|-]               Disable language features to allow better code generation
  /warnaserror[+|-]        Treat warnings as errors
  /w[arn]:<level>          Set warning level (0-4)

                           - MISCELLANEOUS -
  @<filename>              Read response file for more options
  /?                       Display help
  /help                    Display help
  /d[efine]:<symbols>      Define conditional compilation symbol(s)
  /nologo                  Do not display compiler copyright banner
  /print[+|-]              Provide print() function

                           - ADVANCED -
  /codepage:<id>           Use the specified code page ID to open source files
  /lcid:<id>               Use the specified LCID for messages and default code page
  /nostdlib[+|-]           Do not import standard library (mscorlib.dll) and change autoref default to off
  /utf8output[+|-]         Emit compiler output in UTF-8 character encoding
  /versionsafe[+|-]        Specify default for members not marked 'override' or 'hide'

There are usually a couple of copies lying around on any windows install, but they are not usually in the path, so you have to find them.

The compiler is capable of compiling javascript files into executables that can run on any windows machine with .NET installed.

Billy Moon
  • 57,113
  • 24
  • 136
  • 237
10

Node.js works well as an interpreter, even if you do not choose to use it for web applications. It is a framework that runs on the V8 JavaScript engine. It is well documented with a large selection of official and third party modules.

It does require cygwin to run on Windows though (or you can compile it with MingW). There are precompiled binaries, including the required cygwin libraries, available at node-js.prcn.co.cc.

Alex Barrett
  • 16,175
  • 3
  • 52
  • 51
  • 1
    Apparently it doesn't need cygwin any more (2013) - http://stackoverflow.com/questions/10043177/node-js-cygwin-not-supported - and http://en.wikipedia.org/wiki/Nodejs now says "Windows (older versions require Cygwin)" – AjV Jsy Jun 03 '13 at 17:40
4

There are several free standalone Javascript interpreters available:

  1. V8 - This is the same Javascript engine used in the Chrome browser.
  2. SpiderMonkey - From Mozilla.
  3. Rhino - A Javascript implementation on Java.
9716278
  • 2,044
  • 2
  • 14
  • 30
MAK
  • 26,140
  • 11
  • 55
  • 86
  • 1
    Are they available as precompiled binaries? Would a new student to programming be able to download it and compile a "Hello World" program with it? – Ashwin Nanjappa Apr 21 '11 at 09:39
  • @Ashwin if you can follow, find and read documentation then yes. – Raynos Apr 21 '11 at 10:15
  • Raynos: Could you add the links to the pre-built binaries for these interpreters? – Ashwin Nanjappa Apr 21 '11 at 10:36
  • @Raynos: [Rhino](http://www.mozilla.org/rhino/download.html) has got precompiled binaries which you can run if you have a JRE installed in your system. As for the others, I am not sure. But building from source isn't that hard, and is a good thing to learn for any budding programmer. – MAK Apr 21 '11 at 19:30
  • @Ashwin oh sorry, I lied. You can download the V8 source and build it though. Just read .h files for the docs. And good luck. – Raynos Apr 21 '11 at 19:34
  • @Raynos: Sorry my last comment was aimed at @Ashwin. (Too late to edit it now) – MAK Apr 21 '11 at 20:17
3

jsdb is nice. I use it within editplus, sometimes within Aptana Studio

KooiInc
  • 119,216
  • 31
  • 141
  • 177
2

You can also, under some circumstances run JScript scripts (Microsoft's Javascript implementation) directly on the command prompt.

But my personal favourite is Rhino, mentioned in the other answer.

Boldewyn
  • 81,211
  • 44
  • 156
  • 212
  • The window that opens, when you start cmd.exe... If the -1 is from you, could you tell me a bit more concrete, what's wrong with the answer? – Boldewyn Apr 21 '11 at 11:23
  • 3
    "**DOS** box" implies DOS which is officially dead for 4.7 year (MS EoL date for WinME) – user422039 Apr 21 '11 at 20:25
  • 3
    DOS per se, yes, but you still have quite a DOS emulator in cmd.exe. And I read the term 'dos box' as synonym for the console more than once... I'll update the answer nonetheless. – Boldewyn Apr 21 '11 at 20:42
2

Ok, Windows Scripting Host is tool for performing various administrative tasks using Microsoft's Active Scripting and can run scripts in various languages, including JScript, their ECMAScript implementation. There is no much else to say about it, so point your browser to the reference - http://msdn.microsoft.com/en-us/library/shzd7dy4(VS.85).aspx

Forget about compiler, BTW, ECMAScript is interpreted language (JIT compiling is the other issue)

Also, note that ECMAScript standard does not define any standard I/O, so the host program is responsible for providing it.

user422039
  • 1,447
  • 4
  • 13
  • 28
1

I also had the same need but eventually found an app called DeskJS (https://deskjs.wordpress.com). It's a free and portable Windows console application that lets you run pure JavaScript code and even load any existing JS files. It supports the basic JS popup boxes implemented in browsers. You can save your commands as JS files that can be run on startup or by dragging-and-dropping them on the app. Plus there's so much more to it like you can create a build system for Sublime Text that can run JS files via cmd, it supports themes for customizing the entire console and snippets which let you save short snippets of JavaScript code for later use. Improvements are still being made on the app together with other native APIs being included.

js_masher
  • 11
  • 1
1

Perhaps a bit convoluted for what you're looking for but you can use Rhino's JavaScript Compiler to compile JavaScript source code into Java class files which can then be compiled to binary executable programs using the standard GCJ frontend to the GCC compiler suite.

As mentioned by others, the JScript implementation of ECMAScript is available by default on modern Windows installations. Files with a ".js" extension can be double-click executed or run on the command-line using the cscript.exe command.

maerics
  • 151,642
  • 46
  • 269
  • 291
0

Have you tried Mozilla XUL & XULRunner? It is quite more complex than being just an interpreter but it runs also on MacOsX & Linux, not only Windows. Firefox and Thunderbird are written using it (yes, Firefox is written in Javascript!). There will be XUL workshop on FalsyValues conference in Warsaw next month - link.

qqryq
  • 1,814
  • 3
  • 18
  • 20