Computer >> Computer tutorials >  >> Programming >> Javascript

How can I execute JavaScript at the command prompt?


Java SE 8 came with a new engine called Nashorn, which is based on JSR 292. It provides compliance with the ECMA normalized JavaScript.

You can run JavaScript programs from the command line using Nashorn. Include a command-line tool called jjs. The bin folder of a JDK installation has it, with other tools like jar.

Here’s the js file new.js

var display = function() {
   // print “Hello World!” here
};
display();

Run it on a command prompt −

$ jjs new.js
Hello World!
$