JScript .NET, Part X: Displaying Information: Using print() - Doc JavaScript | WebReference

JScript .NET, Part X: Displaying Information: Using print() - Doc JavaScript

JScript .NET, Part X: Displaying Information

Using print()

The most common way to display information is with the print statement. The print statement takes one argument, a string, and displays it in the command-line window, followed by a new line character. The print statement works only with the JScript command-line compiler, jsc. Trying to use print in an ASP.NET page will yield a compiler error. So will an attempt to use it in a Code Behind JScript .NET. Here is a JScript .NET script that uses the print statement:

import System;
class HelloWorld{
  function HelloWorld() {
    print("Object Constructed");
  function TypeHello() {
    print("Hello World.");
var myHelloWorldObj = new HelloWorld();

The program defines a class, HelloWorld, with two methods: the constructor HelloWorld() and TypeHello(). Each of this method prints one string. The constructor prints the message "Object Constructed" when an object of type HelloWorld is constructed. The TypeHello() method prints the message "Hello World". Compiling this program, col116ex2.js, with the jsc compiler yields the default executable col116ex2.exe. When you run this executable (just type col116ex2 at the command line), you'll see the two print messages. The following command-line window shows the code listing, the compilation step, the execution step, and the output of the program:

Next: How to use System.Console

Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: August 12, 2002
Revised: August 12, 2002

URL: http://www.webreference.com/js/column116/2.html