The JScript Version of Hello World!

The following console program is the JScript version of the traditional "Hello World!" program, which displays the string Hello World!.

// A "Hello World!" program in JScript.
print("Hello World!");

The important points of this program are the following:

The first line of the example contains a comment. Since the compiler ignores the comment, you can write any text. This comment describes the purpose of the program.

// A "Hello World!" program in JScript.

The double forward slash (//) means that the rest of the line is a comment. You can make an entire line a comment, or you can append a comment to the end of another statement, as follows:

var area = Math.PI*r*r;  // Area of a circle with radius r.

You can also use multiline comments. A multiline JScript comment begins with a forward slash and asterisk (/*), and ends with the reverse (*/).

/*
Multiline comments allow you to write long comments.
They can also be used to "comment out" blocks of code.
*/

For more information, see JScript Comments.

This example uses the print statement to display the string Hello World!:

print("Hello World!");

For more information, see print Statement.

There are other ways for a program to communicate with the user. The class System.Console exposes methods and properties that facilitate interaction with the person using the console. For more information, see Console. The class System.Windows.Forms.MessageBox exposes methods and properties that facilitate interaction with the user using Windows Forms. For more information, see System.Windows.Forms.

You can compile the "Hello World!" program using the command line compiler.

To compile and run the program from the command line

  1. Create the source file using any text editor and save it using a file name such as Hello.js.

  2. To start the compiler, enter the following at the command prompt:

    jsc Hello.js
    
    NoteNote

    You should compile the program from the Visual Studio Command Prompt. For more information, see How to: Compile JScript Code from the Command Line.

    If your program does not contain compilation errors, the compiler creates a Hello.exe file.

  3. To run the program, enter the following at the command prompt:

    Hello
    
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft