JScript Syntax

The JScript code is written in text format like most other programming languages. It consists of blocks of statements, that, when combined together, create a script. You can find most programming tools within such a block: variables, expressions, calls to functions, and immediate data references such as strings and numbers (also called "literals").

A statement is like a sentence in English, and consists of one or more expressions, operators, keywords, etc. Statements are separated by semicolons ";", and, in most cases, a statement is written using a single line of text. Nevertheless, you can write a statement over two or more lines, most of all to improve the accessibility of it all. It's one thing to have write a statement using a really long line of text, where you must scroll a lot to actually "see it", and it's another to have the same statement written on multiple lines.

In the previous JScript we wrote, you can notice the semicolon at the end of the statement.

Response.Write("Hello World!");

Sometimes, you need to use multiple statements as if they were one. To do this, you must surround all these statements with bracers "{…}"; this is referred to as a block of statements. So even if JScript expects one statement, you can insert a whole block. There are some exceptions to this rule, and some of the most important are the headers of some functions such as "for" and "while". One more thing you might need to know is that, even though a statement ends with a semicolon, this rule does not apply to a block of statements.

Commenting your source code helps a lot. A comment is some text that is not taken into consideration by JScript when it parses the text, so it's there only for the user's "eyes". It helps a lot, as I was saying, because there are times when you want to get back to the script you just wrote, and you need to know what a script or a part of it does without actually browsing through its source code. You might also want to write down to-do's, tips about improvement, etc.

There are two ways you can use comments in JScript: single line comments and multi-line comments. Single-line comments are useful for small comments, when you need to add a to-do or small notice. To define a single line comment, you must add a pair of forward slashes "//", then the comment itself. Multi-line comments are useful for when writing details information about how the code works, copyright information etc. A multi-line comment begins with a forward slash followed by an asterisk "/*", and it ends with the opposite, the asterisk followed by the forward slash "*/". Here are some examples of both types:

/* This is a demo script


It is free of charge, and you can modify it as much as you want.


Copyright(C) softwareprojects 2004


*/


dbName = "database"; //the name of your database


dbHost = "localhost"; //the address of your database server


//to-do: add more info here

blog comments powered by Disqus