Evaluating JavaScript Code with 'jrunscript' Interactively

This section provides a tutorial example on how to evaluate JavaScript codes with 'jrunscript' in interactive mode. Each line is evaluated as an expression. The value is printed on the screen.

Another way to run JavaScrip code with "jrunscript" is to use "jrunscript" in interactive mode. Several notes about using "jrunscript" interactive mode:

I did a number of tests with "jrunscript" interactive mode and recorded some of them below:

C:\herong>\progra~1\java\jdk-10.0.1\bin\jrunscript 

nashorn> println("Hello World!");
Hello World!

nashorn> x = "Apple"; y = "Orange";
Orange

nashorn> println(x + ' and ' + y);
Apple and Orange

nashorn> var s = 0;

nashorn> for ( i=1; i<=100; i++) {
script error: sun.org.mozilla.javascript.internal.EvaluatorException: 
   missing } in compound statement (<STDIN>#1) in <STDIN> at 
   line number 1

nashorn> for ( i=1; i<=100; i++) { s += i; }
5050.0

nashorn> println(s);
5050

js> exit();

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

'jrunscript' - JavaScript Shell Command from JDK

 Downloading and Installing JDK 10

 "jrunscript" - Scripting Shell Command and Options

 Running JavaScript Code with 'jrunscript'

Evaluating JavaScript Code with 'jrunscript' Interactively

 Running a JavaScript Code File with 'jrunscript'

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications

 References

 Full Version in PDF/EPUB