|
Feature |
JScript and Javascript |
VBScript |
|
Example (print 1 to 10 on a web page) |
<html> <body> <% for (i=1; i<=10; i++)
Response.Write(""+i+"<br>") %> </body></html> |
<html> <body> <% for i = 1 to 10 Response.Write(i & "<br>") next %> </body></html> |
|
Script Tags |
<% %>
<%= return expression %> |
<% %>
<%=return expression %> |
|
End of statement |
End of line or optional semicolon |
End of line |
|
Comments |
http://phplens.com/phpeverywhere/node/view///?PHPSESSID=e1ed2daf66b769ae8dd5e164e468ba84 JScript comment /* This is a multi-line Jscript Comment */ |
|
|
Variables |
No prefix |
No prefix |
|
Need to declare variables? |
Optional. Error if variable not initialised when used.
var AVAR |
Optional. Error if variable not initialised when used.
Dim AVAR |
|
Loosely Typed Variables |
Yes |
Yes |
|
Case-Sensitivity |
Yes for variables and reserved words |
No |
|
Strings |
Delimited by single-quotes or double-quotes. |
Delimited by double-quotes. |
|
String Concatenation |
The + (plus) symbol.
s = 'A' + 'B' |
The & (ampersand) symbol.
s = "A" & "B" |
|
String Evaluation |
No |
No |
|
Common string constants |
Line feed: "\n" Carriage return: '\r' |
Line feed: vbLf Carriage return: vbCr |
|
HTML encoding functions |
escape(str) All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding
unescape(str) inverse of escape |
Requires ASP Server object (and consequent COM overhead).
Server.HMTLEncode( ) Similar to PHP's htmlspecialchars.
Server.URLEncode( ) Similar to PHP's urlencode.
|
|
Regular Expressions |
Built-in.
if (str.match(/php/i)) Response.Write("php found") |
Use COM object RegExp. Only available with the latest versions of VBScript (5.5 or later). |
|
Dates |
adate = new Date(); adate = new Date(2000,1,30)
Response.Write(''+adate)
Dates are formated using the current locale configured in the control panel, so you have to hand-code date formatting or change your locale. |
adate = Now date= CDate('2026-1-30') FormatDateTime(adate,2)
Dates are formated using the current locale configured in the control panel, so you have to hand-code date formatting or change your locale. |
|
Arrays |
Declare with avar = new Array(1,'two');
For indexing use [ ]. Arrays begin with zero element.
Use array.length to get size of array. |
Declare with DIM avar(2)
For indexing use ( ). Arrays begin with zero element.
|
|
Associative Arrays |
Yes
avar = new Array(); avar['newton'] = 'isaac'; Response.Write(avar['newton']) |
Not built into the language, but can simulated using the Dictionary object (which is not thread-safe in VBScript 5.0). |
|
True and False |
Has constants true and false.
Empty strings and zero will evaluate to false. |
Has constants true and false.
Unlike PHP and JScript, zero does not evaluate to false. |
|
Equality |
== true if equal != not equal
=== true if equal & same type
!== not identical
JScript does not have the 0/false problem. |
= true if equal <> not equal |
|
Assignment statements |
Allows C style shortcut assignments. For example, to append a string to a variable:
avar += 'append to end'; |
No shortcut assignments. |
|
Sending HTML to Browser |
Response.Write(avar); |
Response.Write(avar); |
|
If statements |
Similar to PHP and C. |
if len(avar) = 0 then avar = "abc" else avar = avar & "end"
endif |
|
While statements |
|
while a > 0 a = a - 1 wend |
|
For loops |
for (i=0,m=9; i<m; i++) { Response.Write(i); } |
for i=1 to 100 Response.Write(i) next |
|
Switch/Case |
switch(aColor) { case 'red': do1 break case 'green': do2 break default: do3; break; } |
select case aColor case "red" do1 case "green" do2 case else do3 end select |