Export (0) Print
Expand All

print Statement

Sends a string to the console followed by a newline character.

function print(str : String)

str

Optional. String to send to the console.

The print statement allows you to display data from a JScript program compiled with the JScript command-line compiler, jsc.exe. The print statement takes a single string as a parameter and displays that string followed by a newline character by sending it to the console.

You can use escape sequences in the strings you pass to the print statement to format the output. Escape sequences are character combinations consisting of a backslash (\) followed by a letter or by a combination of digits. Escape sequences can be used to specify actions such as carriage returns and tab movement. More information about escape characters can be found in the String object topic. The System.Console.WriteLine method can be used when fine control over the format of console output is required.

The print statement is enabled by default in the JScript command-line compiler, jsc.exe. The print statement is disabled in ASP.NET, and you can disable it for the command-line compiler by using the /print- option.

When there is no console to which to print (for example, in a Windows GUI application), the print statement will silently fail.

Output from the print statement can be redirected to a file from the command line. If you expect that the output of a program will be redirected, you should include the \r escape character at the end of each line printed. This causes output redirected to a file to be correctly formatted, and it does not affect the way lines are displayed on the console.

The following example demonstrates a use of the print statement.

var name : String = "Fred";
var age : int = 42;
// Use the \t (tab) and \n (newline) escape sequences to format the output.
print("Name: \t" + name + "\nAge: \t" + age);

The output of this script is:

Name:   Fred
Age:    42

Community Additions

ADD
Show:
© 2014 Microsoft