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>