JavaScript Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.20

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:

  • Each line of code will be evaluated immediately as expressions.
  • Each line of code must be one or multiple complete statements. A single statement can not be entered in multiple lines.
  • If there are multiple expressions involved in a single line of code, the value of the last expression is printed on the screen at the end of the evaluation.

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

C:\herong>\progra~1\java\jdk1.6.0_02\bin\jrunscript 

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

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

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

js> var s = 0;

js> 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

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

js> println(s);
5050

js>

Table of Contents

 About This JavaScript Tutorial Example 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 J2SE 1.6.0 on Windows

 "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

 PDF Printing Version

Dr. Herong Yang, updated in 2008
Evaluating JavaScript Code with 'jrunscript' Interactively